summaryrefslogtreecommitdiffabout
path: root/src
Side-by-side diff
Diffstat (limited to 'src') (more/less context) (ignore 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
@@ -46,97 +46,97 @@ int eyefiService::StartSession(
r.transfermode=transfermode;
r.transfermodetimestamp=transfermodetimestamp;
r.upsyncallowed=false;
std::string cmd = eyekinfig.get_on_start_session();
if(!cmd.empty()) {
if(detached_child()) {
putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) );
putenv( gnu::autosprintf("EYEFI_TRANSFERMODE=%d",transfermode) );
putenv( gnu::autosprintf("EYEFI_TRANSFERMODETIMESTAMP=%ld",transfermodetimestamp) );
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);
}
}
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
eyekinfig_t eyekinfig(macaddress);
umask(eyekinfig.get_umask());
std::string td = eyekinfig.get_targetdir();
tmpdir_t indir(td+"/.incoming.XXXXXX");
std::string tf,lf;
binary_t digest, idigest;
for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) {
#ifndef NDEBUG
syslog(LOG_DEBUG,
" MIME attachment with id=%s, type=%s, size=%ld",
(*i).id, (*i).type, (long)(*i).size );
#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
@@ -18,50 +18,50 @@ eyekinfig_t::eyekinfig_t(const std::string& ma)
};
cfg = cfg_init(opts,CFGF_NONE);
if(!cfg)
throw std::runtime_error("failed to cfg_init()");
std::string::size_type ls = macaddress.rfind('/');
if(cfg_parse(cfg,gnu::autosprintf(
EYEKIN_CONF_DIR "/%s.conf",
(ls==std::string::npos)
? macaddress.c_str()
: macaddress.substr(ls+1).c_str()
)) ==CFG_PARSE_ERROR) {
if(cfg) cfg_free(cfg);
cfg=0;
throw std::runtime_error("failed to cfg_parse()");
}
}
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,105 +1,105 @@
#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;
for(std::string::size_type sl=p.find('/',1);
sl!=std::string::npos;
sl=p.find('/',sl+1)) {
if(stat( (pp=p.substr(0,sl)).c_str() ,&st)
|| !S_ISDIR(st.st_mode)) {
if(mkdir(pp.c_str(),m))
throw std::runtime_error("failed to mkdir()");
}
}
}
tmpdir_t::tmpdir_t(const std::string& dt) : dir(dt) {
make_path_for_template(dt,0777);
if(!mkdtemp((char*)dir.data()))
throw std::runtime_error("failed to mkdtmp()");
}
@@ -113,61 +113,61 @@ tmpdir_t::~tmpdir_t() {
std::string tmpdir_t::get_file(const std::string& f) {
std::string::size_type ls = f.rfind('/');
return dir+'/'+(
(ls==std::string::npos)
? f
: f.substr(ls+1)
);
}
tarchive_t::tarchive_t(void *p,size_t s) : a(archive_read_new()), e(0) {
if(!a) throw std::runtime_error("failed to archive_read_new()");
if(archive_read_support_format_tar(a)) {
archive_read_finish(a);
throw std::runtime_error("failed to archive_read_support_format_tar()");
}
if(archive_read_open_memory(a,p,s)) {
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
@@ -8,79 +8,79 @@
#include "config.h"
#include "eyefi.nsmap"
#define PHEADER \
PACKAGE " Version " VERSION "\n" \
"Copyright (c) 2009 Klever Group"
int main(int argc,char **argv) try {
int port = 59278;
while(true) {
static struct option opts[] = {
{ "help", no_argument, 0, 'h' },
{ "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;
}