summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--src/eyefiservice.cc2
-rw-r--r--src/eyefiworker.cc4
-rw-r--r--src/eyefiworker.h2
-rw-r--r--src/eyekinfig.cc2
-rw-r--r--src/eyetil.cc10
-rw-r--r--src/iiid.cc2
6 files changed, 11 insertions, 11 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc
index 2586ade..e89b2fc 100644
--- a/src/eyefiservice.cc
+++ b/src/eyefiservice.cc
@@ -62,65 +62,65 @@ int eyefiService::StartSession(
return SOAP_OK;
}catch(std::runtime_error& e) {
syslog(LOG_ERR,"error while processing StartSession: %s",e.what());
return soap_receiverfault(e.what(),0);
}
int eyefiService::GetPhotoStatus(
std::string credential, std::string macaddress,
std::string filename, long filesize, std::string filesignature,
int flags,
struct rns__GetPhotoStatusResponse &r ) {
#ifndef NDEBUG
syslog(LOG_DEBUG,
"GetPhotoStatus request from %s with credential=%s, filename=%s, filesize=%ld, filesignature=%s, flags=%d; session nonce=%s",
macaddress.c_str(), credential.c_str(), filename.c_str(), filesize, filesignature.c_str(), flags,
session_nonce.hex().c_str() );
#endif
std::string computed_credential = binary_t(macaddress+eyekinfig_t(macaddress).get_upload_key()+session_nonce.hex()).md5().hex();
#ifndef NDEBUG
syslog(LOG_DEBUG, " computed credential=%s", computed_credential.c_str());
#endif
if (credential != computed_credential) throw std::runtime_error("card authentication failed");
r.fileid = 1; r.offset = 0;
return SOAP_OK;
}
int eyefiService::MarkLastPhotoInRoll(
std::string macaddress, int mergedelta,
- struct rns__MarkLastPhotoInRollResponse &r ) {
+ struct rns__MarkLastPhotoInRollResponse&/* r */ ) {
#ifndef NDEBUG
syslog(LOG_DEBUG,
"MarkLastPhotoInRoll request from %s with mergedelta=%d",
macaddress.c_str(), mergedelta );
#endif
std::string cmd = eyekinfig_t(macaddress).get_on_mark_last_photo_in_roll();
if(!cmd.empty()) {
if(detached_child()) {
putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) );
putenv( gnu::autosprintf("EYEFI_MERGEDELTA=%d",mergedelta) );
char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 };
execv("/bin/sh",argv);
syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str());
_exit(-1);
}
}
keep_alive = 0;
return SOAP_OK;
}
int eyefiService::UploadPhoto(
int fileid, std::string macaddress,
std::string filename, long filesize, std::string filesignature,
std::string encryption, int flags,
struct rns__UploadPhotoResponse& r ) {
#ifndef NDEBUG
syslog(LOG_DEBUG,
"UploadPhoto request from %s with fileid=%d, filename=%s, filesize=%ld,"
" filesignature=%s, encryption=%s, flags=%04X",
macaddress.c_str(), fileid, filename.c_str(), filesize,
filesignature.c_str(), encryption.c_str(), flags );
#endif
diff --git a/src/eyefiworker.cc b/src/eyefiworker.cc
index 2d7827c..c051482 100644
--- a/src/eyefiworker.cc
+++ b/src/eyefiworker.cc
@@ -1,36 +1,36 @@
#include <signal.h>
#include <stdexcept>
#include "eyefiworker.h"
eyefiworker::eyefiworker()
: eyefiService(SOAP_IO_STORE|SOAP_IO_KEEPALIVE) {
bind_flags = SO_REUSEADDR; max_keep_alive = 0;
socket_flags =
#if defined(MSG_NOSIGNAL)
MSG_NOSIGNAL
#elif defined(SO_NOSIGPIPE)
SO_NOSIGPIPE
#else
#error Something is wrong with sigpipe prevention on the platform
#endif
;
}
-int eyefiworker::run(int port) {
- if(!soap_valid_socket(bind(0,port,64)))
+int eyefiworker::run(int bindport) {
+ if(!soap_valid_socket(bind(0,bindport,64)))
throw std::runtime_error("failed to bind()");
signal(SIGCHLD,SIG_IGN);
while(true) {
if(!soap_valid_socket(accept()))
throw std::runtime_error("failed to accept()");
pid_t p = fork();
if(p<0) throw std::runtime_error("failed to fork()");
if(!p) {
recv_timeout = 600; send_timeout = 120;
(void)serve();
soap_destroy(this); soap_end(this); soap_done(this);
_exit(0);
}
close(socket); socket = SOAP_INVALID_SOCKET;
}
}
diff --git a/src/eyefiworker.h b/src/eyefiworker.h
index c08ec8b..afb97c7 100644
--- a/src/eyefiworker.h
+++ b/src/eyefiworker.h
@@ -1,15 +1,15 @@
#ifndef __EYEFIWORKER_H
#define __EYEFIWORKER_H
#include "soapeyefiService.h"
class eyefiworker : public eyefiService {
public:
eyefiworker();
- int run(int port);
+ int run(int port) __attribute__ ((noreturn));
};
#endif /* __EYEFIWORKER_H */
diff --git a/src/eyekinfig.cc b/src/eyekinfig.cc
index 27a5a56..56c74a7 100644
--- a/src/eyekinfig.cc
+++ b/src/eyekinfig.cc
@@ -34,34 +34,34 @@ eyekinfig_t::eyekinfig_t(const std::string& ma)
eyekinfig_t::~eyekinfig_t() {
if(cfg) cfg_free(cfg);
}
std::string eyekinfig_t::get_targetdir() {
assert(cfg);
return gnu::autosprintf(cfg_getstr(cfg,"targetdir"),macaddress.c_str());
}
std::string eyekinfig_t::get_upload_key() {
assert(cfg);
return cfg_getstr(cfg,"uploadkey");
}
std::string eyekinfig_t::get_on_start_session() {
assert(cfg);
return cfg_getstr(cfg,"on-start-session");
}
std::string eyekinfig_t::get_on_upload_photo() {
assert(cfg);
return cfg_getstr(cfg,"on-upload-photo");
}
std::string eyekinfig_t::get_on_mark_last_photo_in_roll() {
assert(cfg);
return cfg_getstr(cfg,"on-mark-last-photo-in-roll");
}
int eyekinfig_t::get_umask() {
assert(cfg);
- return cfg_getint(cfg,"umask");
+ return 0777&cfg_getint(cfg,"umask");
}
diff --git a/src/eyetil.cc b/src/eyetil.cc
index 2e6ab7e..11e2fb7 100644
--- a/src/eyetil.cc
+++ b/src/eyetil.cc
@@ -1,89 +1,89 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <syslog.h>
#include <iostream>
#include <cassert>
#include <stdexcept>
#include <algorithm>
#include <numeric>
#include <openssl/md5.h>
#include "eyetil.h"
#include "config.h"
#ifdef HAVE_LIBUUID
# include <uuid/uuid.h>
#endif
binary_t& binary_t::from_hex(const std::string& h) {
std::string::size_type hs = h.length();
if(hs&1)
throw std::runtime_error("odd number of characters in hexadecimal number");
- int rvs = hs>>1;
+ size_t rvs = hs>>1;
resize(rvs);
const unsigned char *hp = (const unsigned char*)h.data();
iterator oi=begin();
char t[3] = { 0,0,0 };
- for(int i=0;i<rvs;++i) {
+ for(size_t i=0;i<rvs;++i) {
t[0]=*(hp++); t[1]=*(hp++);
- *(oi++) = strtol(t,0,16);
+ *(oi++) = static_cast<binary_t::value_type>(0xff&strtol(t,0,16));
}
return *this;
}
binary_t& binary_t::from_data(const void *d,size_t s) {
resize(s);
std::copy((const unsigned char*)d,(const unsigned char *)d+s,
begin() );
return *this;
}
binary_t& binary_t::make_nonce() {
#ifdef HAVE_LIBUUID
uuid_t uuid;
uuid_generate(uuid);
from_data((unsigned char*)uuid,sizeof(uuid));
#else
resize(16);
std::generate_n(begin(),16,rand);
#endif /* HAVE_LIBUUID */
return *this;
}
std::string binary_t::hex() const {
std::string rv;
rv.reserve((size()<<1)+1);
char t[3] = {0,0,0};
for(const_iterator i=begin(),ie=end();i!=ie;++i) {
- int rc = snprintf(t,sizeof(t),"%02x",*i);
+ size_t rc = snprintf(t,sizeof(t),"%02x",*i);
assert(rc<sizeof(t));
rv += t;
}
return rv;
}
binary_t binary_t::md5() const {
binary_t rv(MD5_DIGEST_LENGTH);
if(!MD5(
(const unsigned char*)&(front()),size(),
(unsigned char*)&(rv.front()) ))
throw std::runtime_error("failed to md5()");
return rv;
}
void md5_digester::init() {
if(!MD5_Init(&ctx)) throw std::runtime_error("failed to MD5_Init()");
}
void md5_digester::update(const void *d,size_t l) {
if(!MD5_Update(&ctx,d,l)) throw std::runtime_error("failed to MD5_Update()");
}
binary_t md5_digester::final() {
binary_t rv(MD5_DIGEST_LENGTH);
if(!MD5_Final((unsigned char*)&(rv.front()), &ctx))
throw std::runtime_error("failed to MD5_Final()");
return rv;
}
static void make_path_for_template(const std::string& p,mode_t m) {
struct stat st;
std::string pp;
@@ -129,45 +129,45 @@ tarchive_t::tarchive_t(void *p,size_t s) : a(archive_read_new()), e(0) {
archive_read_finish(a);
throw std::runtime_error("failed to archive_read_open_memory()");
}
}
tarchive_t::~tarchive_t() {
assert(a);
archive_read_finish(a);
}
bool tarchive_t::read_next_header() {
assert(a);
return archive_read_next_header(a,&e)==ARCHIVE_OK;
}
std::string tarchive_t::entry_pathname() {
assert(a); assert(e);
return archive_entry_pathname(e);
}
bool tarchive_t::read_data_into_fd(int fd) {
assert(a);
return archive_read_data_into_fd(a,fd)==ARCHIVE_OK;
}
#pragma pack(1)
struct block512_t {
enum { words = 512 / sizeof(uint16_t) };
uint16_t data[words];
static uint16_t tcpcksum(block512_t& data) {
uint32_t sum = std::accumulate(data.data,data.data+words,0);
while(uint32_t hw = sum>>16) sum = (sum&0xffff)+hw;
- return ~sum;
+ return 0xffff&~sum;
}
};
#pragma pack()
binary_t integrity_digest(const void *ptr,size_t size,const std::string& ukey) {
md5_digester rv;
std::transform( (block512_t*)ptr, ((block512_t*)ptr)+size/sizeof(block512_t),
rv.updater<uint16_t>(), block512_t::tcpcksum );
rv.update( binary_t(ukey) );
return rv.final();
}
diff --git a/src/iiid.cc b/src/iiid.cc
index 6c23790..c026050 100644
--- a/src/iiid.cc
+++ b/src/iiid.cc
@@ -24,63 +24,63 @@ int main(int argc,char **argv) try {
{ "usage", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'V' },
{ "license", no_argument, 0, 'L' },
{ "port", required_argument, 0, 'p' },
{ NULL, 0, 0, 0 }
};
int c = getopt_long(argc,argv,"hVLp:",opts,NULL);
if(c==-1) break;
switch(c) {
case 'h':
std::cerr << PHEADER << std::endl << std::endl
<< " " << argv[0] << " [options]" << std::endl
<< std::endl <<
" -h, --help,\n"
" --usage display this text\n"
" -V, --version display version information\n"
" -L, --license show license\n"
" -p <port>, --port=<port> port to listen to\n"
" (you're not likely to ever need it)\n"
<< std::endl << std::endl;
exit(0);
break;
case 'V':
std::cerr << VERSION << std::endl;
exit(0);
break;
case 'L':
extern const char *COPYING;
std::cerr << COPYING << std::endl;
exit(0);
break;
case 'p':
- port = strtol(optarg,0,0);
+ port = 0xffff&strtol(optarg,0,0);
if(errno) {
std::cerr << "Failed to parse port number" << std::endl;
exit(1);
}
break;
default:
std::cerr << "Huh?" << std::endl;
exit(1);
break;
}
}
const char *ident = rindex(*argv,'/');
if(ident)
++ident;
else
ident = *argv;
openlog(ident,LOG_PERROR|LOG_PID,LOG_DAEMON);
syslog(LOG_INFO,"Starting iii eye-fi manager");
eyefiworker().run(port);
closelog();
return 0;
} catch(std::exception& e) {
syslog(LOG_CRIT,"Exiting iii daemon, because of error condition");
syslog(LOG_CRIT,"Exception: %s",e.what());
return 1;
}