summaryrefslogtreecommitdiffabout
path: root/src
authorMichael Krelin <hacker@klever.net>2011-03-19 17:25:00 (UTC)
committer Michael Krelin <hacker@klever.net>2011-03-19 17:52:04 (UTC)
commit5ca0d6a85c438ea75dc2795aca5176e3b31e89f0 (patch) (unidiff)
treef35c09c1d07c2150d4d0a58a517b878a44591cc8 /src
parentc295320edf2d733a12a622c5a721c8431800a68a (diff)
downloadiii-5ca0d6a85c438ea75dc2795aca5176e3b31e89f0.zip
iii-5ca0d6a85c438ea75dc2795aca5176e3b31e89f0.tar.gz
iii-5ca0d6a85c438ea75dc2795aca5176e3b31e89f0.tar.bz2
linting debian stuff
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyefiservice.cc1
1 files changed, 0 insertions, 1 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc
index 49521e0..9650ec1 100644
--- a/src/eyefiservice.cc
+++ b/src/eyefiservice.cc
@@ -1,105 +1,104 @@
1#include <cassert> 1#include <cassert>
2#include <iostream> 2#include <iostream>
3#include <fstream> 3#include <fstream>
4#include <stdexcept> 4#include <stdexcept>
5#include <iterator> 5#include <iterator>
6#include <syslog.h> 6#include <syslog.h>
7#include <sys/wait.h> 7#include <sys/wait.h>
8#include <autosprintf.h> 8#include <autosprintf.h>
9#include <openssl/rand.h>
10#include "eyekinfig.h" 9#include "eyekinfig.h"
11#include "eyetil.h" 10#include "eyetil.h"
12#include "soapeyefiService.h" 11#include "soapeyefiService.h"
13 12
14static binary_t session_nonce; 13static binary_t session_nonce;
15 14
16static bool detached_child() { 15static bool detached_child() {
17 pid_t p = fork(); 16 pid_t p = fork();
18 if(p<0) throw std::runtime_error("failed to fork()"); 17 if(p<0) throw std::runtime_error("failed to fork()");
19 if(!p) { 18 if(!p) {
20 p = fork(); 19 p = fork();
21 if(p<0) { 20 if(p<0) {
22 syslog(LOG_ERR,"Failed to re-fork child process"); 21 syslog(LOG_ERR,"Failed to re-fork child process");
23 _exit(-1); 22 _exit(-1);
24 } 23 }
25 if(!p) { 24 if(!p) {
26 setsid(); 25 setsid();
27 for(int i=getdtablesize();i>=0;--i) close(i); 26 for(int i=getdtablesize();i>=0;--i) close(i);
28 int i=open("/dev/null",O_RDWR); assert(i==0); 27 int i=open("/dev/null",O_RDWR); assert(i==0);
29 i = dup(i); assert(i==1); 28 i = dup(i); assert(i==1);
30 i = dup(i); assert(i==2); 29 i = dup(i); assert(i==2);
31 return true; 30 return true;
32 } 31 }
33 _exit(0); 32 _exit(0);
34 } 33 }
35 int rc; 34 int rc;
36 if(waitpid(p,&rc,0)<0) throw std::runtime_error("failed to waitpid()"); 35 if(waitpid(p,&rc,0)<0) throw std::runtime_error("failed to waitpid()");
37 if(!WIFEXITED(rc)) throw std::runtime_error("error in forked process"); 36 if(!WIFEXITED(rc)) throw std::runtime_error("error in forked process");
38 if(WEXITSTATUS(rc)) throw std::runtime_error("forked process signalled error"); 37 if(WEXITSTATUS(rc)) throw std::runtime_error("forked process signalled error");
39 return false; 38 return false;
40} 39}
41 40
42int eyefiService::StartSession( 41int eyefiService::StartSession(
43 std::string macaddress,std::string cnonce, 42 std::string macaddress,std::string cnonce,
44 int transfermode,long transfermodetimestamp, 43 int transfermode,long transfermodetimestamp,
45 struct rns__StartSessionResponse &r ) try { 44 struct rns__StartSessionResponse &r ) try {
46#ifndef NDEBUG 45#ifndef NDEBUG
47 syslog(LOG_DEBUG, 46 syslog(LOG_DEBUG,
48 "StartSession request from %s with cnonce=%s, transfermode=%d, transfermodetimestamp=%ld", 47 "StartSession request from %s with cnonce=%s, transfermode=%d, transfermodetimestamp=%ld",
49 macaddress.c_str(), cnonce.c_str(), transfermode, transfermodetimestamp ); 48 macaddress.c_str(), cnonce.c_str(), transfermode, transfermodetimestamp );
50#endif 49#endif
51 eyekinfig_t eyekinfig(macaddress); 50 eyekinfig_t eyekinfig(macaddress);
52 r.credential = binary_t(macaddress+cnonce+eyekinfig.get_upload_key()).md5().hex(); 51 r.credential = binary_t(macaddress+cnonce+eyekinfig.get_upload_key()).md5().hex();
53 52
54 r.snonce = session_nonce.make_nonce().hex(); 53 r.snonce = session_nonce.make_nonce().hex();
55 r.transfermode=transfermode; 54 r.transfermode=transfermode;
56 r.transfermodetimestamp=transfermodetimestamp; 55 r.transfermodetimestamp=transfermodetimestamp;
57 r.upsyncallowed=false; 56 r.upsyncallowed=false;
58 57
59 std::string cmd = eyekinfig.get_on_start_session(); 58 std::string cmd = eyekinfig.get_on_start_session();
60 if(!cmd.empty()) { 59 if(!cmd.empty()) {
61 if(detached_child()) { 60 if(detached_child()) {
62 putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) ); 61 putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) );
63 putenv( gnu::autosprintf("EYEFI_TRANSFERMODE=%d",transfermode) ); 62 putenv( gnu::autosprintf("EYEFI_TRANSFERMODE=%d",transfermode) );
64 putenv( gnu::autosprintf("EYEFI_TRANSFERMODETIMESTAMP=%ld",transfermodetimestamp) ); 63 putenv( gnu::autosprintf("EYEFI_TRANSFERMODETIMESTAMP=%ld",transfermodetimestamp) );
65 char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 }; 64 char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 };
66 execv("/bin/sh",argv); 65 execv("/bin/sh",argv);
67 syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str()); 66 syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str());
68 _exit(-1); 67 _exit(-1);
69 } 68 }
70 } 69 }
71 return SOAP_OK; 70 return SOAP_OK;
72}catch(std::runtime_error& e) { 71}catch(std::runtime_error& e) {
73 syslog(LOG_ERR,"error while processing StartSession: %s",e.what()); 72 syslog(LOG_ERR,"error while processing StartSession: %s",e.what());
74} 73}
75 74
76int eyefiService::GetPhotoStatus( 75int eyefiService::GetPhotoStatus(
77 std::string credential, std::string macaddress, 76 std::string credential, std::string macaddress,
78 std::string filename, long filesize, std::string filesignature, 77 std::string filename, long filesize, std::string filesignature,
79 int flags, 78 int flags,
80 struct rns__GetPhotoStatusResponse &r ) { 79 struct rns__GetPhotoStatusResponse &r ) {
81#ifndef NDEBUG 80#ifndef NDEBUG
82 syslog(LOG_DEBUG, 81 syslog(LOG_DEBUG,
83 "GetPhotoStatus request from %s with credential=%s, filename=%s, filesize=%ld, filesignature=%s, flags=%d; session nonce=%s", 82 "GetPhotoStatus request from %s with credential=%s, filename=%s, filesize=%ld, filesignature=%s, flags=%d; session nonce=%s",
84 macaddress.c_str(), credential.c_str(), filename.c_str(), filesize, filesignature.c_str(), flags, 83 macaddress.c_str(), credential.c_str(), filename.c_str(), filesize, filesignature.c_str(), flags,
85 session_nonce.hex().c_str() ); 84 session_nonce.hex().c_str() );
86#endif 85#endif
87 86
88 std::string computed_credential = binary_t(macaddress+eyekinfig_t(macaddress).get_upload_key()+session_nonce.hex()).md5().hex(); 87 std::string computed_credential = binary_t(macaddress+eyekinfig_t(macaddress).get_upload_key()+session_nonce.hex()).md5().hex();
89 88
90#ifndef NDEBUG 89#ifndef NDEBUG
91 syslog(LOG_DEBUG, " computed credential=%s", computed_credential.c_str()); 90 syslog(LOG_DEBUG, " computed credential=%s", computed_credential.c_str());
92#endif 91#endif
93 92
94 if (credential != computed_credential) throw std::runtime_error("card authentication failed"); 93 if (credential != computed_credential) throw std::runtime_error("card authentication failed");
95 94
96 r.fileid = 1; r.offset = 0; 95 r.fileid = 1; r.offset = 0;
97 return SOAP_OK; 96 return SOAP_OK;
98} 97}
99 98
100int eyefiService::MarkLastPhotoInRoll( 99int eyefiService::MarkLastPhotoInRoll(
101 std::string macaddress, int mergedelta, 100 std::string macaddress, int mergedelta,
102 struct rns__MarkLastPhotoInRollResponse &r ) { 101 struct rns__MarkLastPhotoInRollResponse &r ) {
103#ifndef NDEBUG 102#ifndef NDEBUG
104 syslog(LOG_DEBUG, 103 syslog(LOG_DEBUG,
105 "MarkLastPhotoInRoll request from %s with mergedelta=%d", 104 "MarkLastPhotoInRoll request from %s with mergedelta=%d",