author | Michael Krelin <hacker@klever.net> | 2011-03-19 17:25:00 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2011-03-19 17:52:04 (UTC) |
commit | 5ca0d6a85c438ea75dc2795aca5176e3b31e89f0 (patch) (unidiff) | |
tree | f35c09c1d07c2150d4d0a58a517b878a44591cc8 | |
parent | c295320edf2d733a12a622c5a721c8431800a68a (diff) | |
download | iii-5ca0d6a85c438ea75dc2795aca5176e3b31e89f0.zip iii-5ca0d6a85c438ea75dc2795aca5176e3b31e89f0.tar.gz iii-5ca0d6a85c438ea75dc2795aca5176e3b31e89f0.tar.bz2 |
linting debian stuff
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | debian/compat | 2 | ||||
-rw-r--r-- | debian/control | 4 | ||||
-rwxr-xr-x | debian/iii.postinst | 2 | ||||
-rwxr-xr-x | debian/iii.postrm | 1 | ||||
-rw-r--r-- | debian/source/format | 1 | ||||
-rw-r--r-- | doc/000000000000.conf | 2 | ||||
-rw-r--r-- | src/eyefiservice.cc | 1 |
8 files changed, 8 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac index d580f58..f79983e 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,75 +1,75 @@ | |||
1 | AC_INIT([iii], [0.2], [iii-bugs@klever.net]) | 1 | AC_INIT([iii], [0.2], [iii-bugs@klever.net]) |
2 | AC_CONFIG_SRCDIR([src/iiid.cc]) | 2 | AC_CONFIG_SRCDIR([src/iiid.cc]) |
3 | AC_CONFIG_HEADERS([config.h]) | 3 | AC_CONFIG_HEADERS([config.h]) |
4 | AM_INIT_AUTOMAKE([dist-bzip2]) | 4 | AM_INIT_AUTOMAKE([dist-bzip2]) |
5 | 5 | ||
6 | AC_PROG_INSTALL | 6 | AC_PROG_INSTALL |
7 | AC_PROG_CXX | 7 | AC_PROG_CXX |
8 | AC_PROG_CC | 8 | AC_PROG_CC |
9 | PKG_PROG_PKG_CONFIG | 9 | PKG_PROG_PKG_CONFIG |
10 | 10 | ||
11 | AC_HEADER_STDC | 11 | AC_HEADER_STDC |
12 | 12 | ||
13 | AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) | 13 | AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) |
14 | 14 | ||
15 | PKG_CHECK_MODULES([MODULES],[gsoap++ openssl libconfuse]) | 15 | PKG_CHECK_MODULES([MODULES],[gsoap++ libcrypto libconfuse]) |
16 | PKG_CHECK_MODULES([UUID],[uuid],[have_uuid=true],[have_uuid=false]) | 16 | PKG_CHECK_MODULES([UUID],[uuid],[have_uuid=true],[have_uuid=false]) |
17 | AM_CONDITIONAL([HAVE_UUID],[$have_uuid]) | 17 | AM_CONDITIONAL([HAVE_UUID],[$have_uuid]) |
18 | if $have_uuid ; then | 18 | if $have_uuid ; then |
19 | AC_DEFINE([HAVE_LIBUUID],,[defined in presence of libuuid]) | 19 | AC_DEFINE([HAVE_LIBUUID],,[defined in presence of libuuid]) |
20 | AC_SUBST([UUID_UUID],[uuid]) | 20 | AC_SUBST([UUID_UUID],[uuid]) |
21 | fi | 21 | fi |
22 | 22 | ||
23 | AC_PATH_PROG([SOAPCPP2],[soapcpp2],[false]) | 23 | AC_PATH_PROG([SOAPCPP2],[soapcpp2],[false]) |
24 | test "$SOAPCPP2" = "false" && AC_MSG_ERROR([no soapcpp2 tool, part of gsoap package, found.]) | 24 | test "$SOAPCPP2" = "false" && AC_MSG_ERROR([no soapcpp2 tool, part of gsoap package, found.]) |
25 | 25 | ||
26 | notfound=false | 26 | notfound=false |
27 | AC_CHECK_HEADERS([archive.h],[ | 27 | AC_CHECK_HEADERS([archive.h],[ |
28 | AC_CHECK_LIB([archive],[archive_read_new],,[notfound=true]) | 28 | AC_CHECK_LIB([archive],[archive_read_new],,[notfound=true]) |
29 | ],[notfound=true]) | 29 | ],[notfound=true]) |
30 | $notfound && AC_MSG_ERROR([no required libarchive library found. get one from http://people.freebsd.org/~kientzle/libarchive/]) | 30 | $notfound && AC_MSG_ERROR([no required libarchive library found. get one from http://people.freebsd.org/~kientzle/libarchive/]) |
31 | 31 | ||
32 | notfound=false | 32 | notfound=false |
33 | AC_LANG_PUSH([C++]) | 33 | AC_LANG_PUSH([C++]) |
34 | AC_CHECK_HEADERS([autosprintf.h],[ | 34 | AC_CHECK_HEADERS([autosprintf.h],[ |
35 | AC_CHECK_LIB([asprintf],[main],,[notfound=true]) | 35 | AC_CHECK_LIB([asprintf],[main],,[notfound=true]) |
36 | ],[notfound=true]) | 36 | ],[notfound=true]) |
37 | $notfound && AC_MSG_ERROR([no autosprintf, part of gettext, found]) | 37 | $notfound && AC_MSG_ERROR([no autosprintf, part of gettext, found]) |
38 | AC_LANG_POP([C++]) | 38 | AC_LANG_POP([C++]) |
39 | 39 | ||
40 | nitpick=false | 40 | nitpick=false |
41 | AC_ARG_ENABLE([nitpicking], | 41 | AC_ARG_ENABLE([nitpicking], |
42 | AC_HELP_STRING([--enable-nitpicking],[make compiler somewhat overly fastidious about the code it deals with]), | 42 | AC_HELP_STRING([--enable-nitpicking],[make compiler somewhat overly fastidious about the code it deals with]), |
43 | [ test "$enableval" = "no" || nitpick=true ] | 43 | [ test "$enableval" = "no" || nitpick=true ] |
44 | ) | 44 | ) |
45 | if $nitpick ; then | 45 | if $nitpick ; then |
46 | CPP_NITPICK="-pedantic -Wall -Wextra -Wundef -Wshadow \ | 46 | CPP_NITPICK="-pedantic -Wall -Wextra -Wundef -Wshadow \ |
47 | -Wunsafe-loop-optimizations -Wconversion -Wmissing-format-attribute \ | 47 | -Wunsafe-loop-optimizations -Wconversion -Wmissing-format-attribute \ |
48 | -Wredundant-decls -ansi -Wlogical-op -Wmissing-noreturn" | 48 | -Wredundant-decls -ansi -Wlogical-op -Wmissing-noreturn" |
49 | C_NITPICK="$CPP_NITPICK" | 49 | C_NITPICK="$CPP_NITPICK" |
50 | CXX_NITPICK="$C_NITPICK" | 50 | CXX_NITPICK="$C_NITPICK" |
51 | 51 | ||
52 | CPPFLAGS="$CPPFLAGS $CPP_NITPICK" | 52 | CPPFLAGS="$CPPFLAGS $CPP_NITPICK" |
53 | CFLAGS="$CFLAGS $C_NITPICK" | 53 | CFLAGS="$CFLAGS $C_NITPICK" |
54 | CXXFLAGS="$CXXFLAGS $CXX_NITPICK" | 54 | CXXFLAGS="$CXXFLAGS $CXX_NITPICK" |
55 | fi | 55 | fi |
56 | 56 | ||
57 | ndebug=true | 57 | ndebug=true |
58 | AC_ARG_ENABLE([debug], | 58 | AC_ARG_ENABLE([debug], |
59 | AC_HELP_STRING([--enable-debug],[enable debugging code]), | 59 | AC_HELP_STRING([--enable-debug],[enable debugging code]), |
60 | [ test "$enableval" = "no" || ndebug=false ] | 60 | [ test "$enableval" = "no" || ndebug=false ] |
61 | ) | 61 | ) |
62 | if $ndebug ; then | 62 | if $ndebug ; then |
63 | CPPFLAGS_DEBUG="-DNDEBUG" | 63 | CPPFLAGS_DEBUG="-DNDEBUG" |
64 | else | 64 | else |
65 | CPPFLAGS_DEBUG="-DDEBUG" | 65 | CPPFLAGS_DEBUG="-DDEBUG" |
66 | fi | 66 | fi |
67 | AC_SUBST([CPPFLAGS_DEBUG]) | 67 | AC_SUBST([CPPFLAGS_DEBUG]) |
68 | 68 | ||
69 | AC_CONFIG_FILES([ | 69 | AC_CONFIG_FILES([ |
70 | Makefile | 70 | Makefile |
71 | src/Makefile | 71 | src/Makefile |
72 | doc/Makefile | 72 | doc/Makefile |
73 | doc/iiid.8 | 73 | doc/iiid.8 |
74 | ]) | 74 | ]) |
75 | AC_OUTPUT | 75 | AC_OUTPUT |
diff --git a/debian/compat b/debian/compat index b8626c4..7ed6ff8 100644 --- a/debian/compat +++ b/debian/compat | |||
@@ -1 +1 @@ | |||
4 | 5 | ||
diff --git a/debian/control b/debian/control index 02a6138..aaa8c78 100644 --- a/debian/control +++ b/debian/control | |||
@@ -1,13 +1,13 @@ | |||
1 | Source: iii | 1 | Source: iii |
2 | Section: graphics | 2 | Section: graphics |
3 | Priority: optional | 3 | Priority: optional |
4 | Maintainer: Michael Krelin <hacker@klever.net> | 4 | Maintainer: Michael Krelin <hacker@klever.net> |
5 | Build-Depends: debhelper (>=7), gsoap, libssl-dev, libconfuse-dev, libarchive-dev, gettext | 5 | Build-Depends: debhelper (>=7), gsoap, libssl-dev, libconfuse-dev, libarchive-dev, gettext |
6 | Standards-Version: 3.8.0 | 6 | Standards-Version: 3.8.4 |
7 | 7 | ||
8 | Package: iii | 8 | Package: iii |
9 | Architecture: any | 9 | Architecture: any |
10 | Depends: adduser, ${shlibs:Depends} | 10 | Depends: adduser, ${shlibs:Depends}, ${misc:Depends} |
11 | Description: Eye-Fi Manager implementation | 11 | Description: Eye-Fi Manager implementation |
12 | Implementation of Eye-Fi manager service for Linux | 12 | Implementation of Eye-Fi manager service for Linux |
13 | 13 | ||
diff --git a/debian/iii.postinst b/debian/iii.postinst index 20463a1..f52bf84 100755 --- a/debian/iii.postinst +++ b/debian/iii.postinst | |||
@@ -1,18 +1,18 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | set -e | 2 | set -e |
3 | UG=eyefi | 3 | UG=eyefi |
4 | P=eyekindo | 4 | P=iii |
5 | H=/var/lib/$P | 5 | H=/var/lib/$P |
6 | 6 | ||
7 | if [ "$1" = configure ] ; then | 7 | if [ "$1" = configure ] ; then |
8 | getent group $UG >/dev/null 2>&1 || addgroup --system $UG | 8 | getent group $UG >/dev/null 2>&1 || addgroup --system $UG |
9 | getent passwd $UG >/dev/null 2>&1 || adduser --system --home $H \ | 9 | getent passwd $UG >/dev/null 2>&1 || adduser --system --home $H \ |
10 | --no-create-home --disabled-password --ingroup $UG $UG | 10 | --no-create-home --disabled-password --ingroup $UG $UG |
11 | if ! test -d $H ; then | 11 | if ! test -d $H ; then |
12 | mkdir -p $H | 12 | mkdir -p $H |
13 | chown $UG:$UG $H | 13 | chown $UG:$UG $H |
14 | chmod 2770 $H | 14 | chmod 2770 $H |
15 | fi | 15 | fi |
16 | fi | 16 | fi |
17 | 17 | ||
18 | #DEBHELPER# | 18 | #DEBHELPER# |
diff --git a/debian/iii.postrm b/debian/iii.postrm index a2c66fa..6060c4f 100755 --- a/debian/iii.postrm +++ b/debian/iii.postrm | |||
@@ -1,3 +1,4 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | set -e | ||
2 | 3 | ||
3 | #DEBHELPER# | 4 | #DEBHELPER# |
diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- a/dev/null +++ b/debian/source/format | |||
@@ -0,0 +1 @@ | |||
3.0 (native) | |||
diff --git a/doc/000000000000.conf b/doc/000000000000.conf index d7b365f..01f8fae 100644 --- a/doc/000000000000.conf +++ b/doc/000000000000.conf | |||
@@ -1,17 +1,17 @@ | |||
1 | # target directory for uploaded files, if the name contains %s, it is replaced | 1 | # target directory for uploaded files, if the name contains %s, it is replaced |
2 | # with eyefi card mac address. | 2 | # with eyefi card mac address. |
3 | targetdir = "/var/lib/eyekindo/%s/" | 3 | targetdir = "/var/lib/iii/%s/" |
4 | # the upload key as seen in Mac and (perhaps) windows Settings.xml file | 4 | # the upload key as seen in Mac and (perhaps) windows Settings.xml file |
5 | uploadkey = "e3e2c4a305cee6bce0ebb38a3259ac08" | 5 | uploadkey = "e3e2c4a305cee6bce0ebb38a3259ac08" |
6 | 6 | ||
7 | # commands to be executed at certain events, the commands also receive certain | 7 | # commands to be executed at certain events, the commands also receive certain |
8 | # values of interested passed via environment. | 8 | # values of interested passed via environment. |
9 | # for on-start-session: EYEFI_MACADDRESS, EYEFI_TRANSFER_MODE, EYEFI_TRANSFERMODETIMESTAMP | 9 | # for on-start-session: EYEFI_MACADDRESS, EYEFI_TRANSFER_MODE, EYEFI_TRANSFERMODETIMESTAMP |
10 | on-start-session = "bash /usr/local/lib/iii/on-start-session.bash" | 10 | on-start-session = "bash /usr/local/lib/iii/on-start-session.bash" |
11 | # for on-upload-photo: EYEFI_MACADDRESS, EYEFI_UPLOADED (uploaded file name) | 11 | # for on-upload-photo: EYEFI_MACADDRESS, EYEFI_UPLOADED (uploaded file name) |
12 | on-upload-photo = "bash /usr/local/lib/iii/on-upload-photo.bash" | 12 | on-upload-photo = "bash /usr/local/lib/iii/on-upload-photo.bash" |
13 | # for on-mark-last-photo-in-roll: EYEFI_MACADDRESS, EYEFI_MERGEDELTA | 13 | # for on-mark-last-photo-in-roll: EYEFI_MACADDRESS, EYEFI_MERGEDELTA |
14 | on-mark-last-photo-in-roll = "bash /usr/local/lib/iii/on-mark-last-photo-in-roll.bash" | 14 | on-mark-last-photo-in-roll = "bash /usr/local/lib/iii/on-mark-last-photo-in-roll.bash" |
15 | 15 | ||
16 | # file mode creation mask | 16 | # file mode creation mask |
17 | umask = 002 | 17 | umask = 002 |
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc index 49521e0..9650ec1 100644 --- a/src/eyefiservice.cc +++ b/src/eyefiservice.cc | |||
@@ -1,201 +1,200 @@ | |||
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 | ||
14 | static binary_t session_nonce; | 13 | static binary_t session_nonce; |
15 | 14 | ||
16 | static bool detached_child() { | 15 | static 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 | ||
42 | int eyefiService::StartSession( | 41 | int 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 | ||
76 | int eyefiService::GetPhotoStatus( | 75 | int 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 | ||
100 | int eyefiService::MarkLastPhotoInRoll( | 99 | int 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", |
106 | macaddress.c_str(), mergedelta ); | 105 | macaddress.c_str(), mergedelta ); |
107 | #endif | 106 | #endif |
108 | std::string cmd = eyekinfig_t(macaddress).get_on_mark_last_photo_in_roll(); | 107 | std::string cmd = eyekinfig_t(macaddress).get_on_mark_last_photo_in_roll(); |
109 | if(!cmd.empty()) { | 108 | if(!cmd.empty()) { |
110 | if(detached_child()) { | 109 | if(detached_child()) { |
111 | putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) ); | 110 | putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) ); |
112 | putenv( gnu::autosprintf("EYEFI_MERGEDELTA=%d",mergedelta) ); | 111 | putenv( gnu::autosprintf("EYEFI_MERGEDELTA=%d",mergedelta) ); |
113 | char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 }; | 112 | char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 }; |
114 | execv("/bin/sh",argv); | 113 | execv("/bin/sh",argv); |
115 | syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str()); | 114 | syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str()); |
116 | _exit(-1); | 115 | _exit(-1); |
117 | } | 116 | } |
118 | } | 117 | } |
119 | return SOAP_OK; | 118 | return SOAP_OK; |
120 | } | 119 | } |
121 | 120 | ||
122 | int eyefiService::UploadPhoto( | 121 | int eyefiService::UploadPhoto( |
123 | int fileid, std::string macaddress, | 122 | int fileid, std::string macaddress, |
124 | std::string filename, long filesize, std::string filesignature, | 123 | std::string filename, long filesize, std::string filesignature, |
125 | std::string encryption, int flags, | 124 | std::string encryption, int flags, |
126 | struct rns__UploadPhotoResponse& r ) { | 125 | struct rns__UploadPhotoResponse& r ) { |
127 | #ifndef NDEBUG | 126 | #ifndef NDEBUG |
128 | syslog(LOG_DEBUG, | 127 | syslog(LOG_DEBUG, |
129 | "UploadPhoto request from %s with fileid=%d, filename=%s, filesize=%ld," | 128 | "UploadPhoto request from %s with fileid=%d, filename=%s, filesize=%ld," |
130 | " filesignature=%s, encryption=%s, flags=%04X", | 129 | " filesignature=%s, encryption=%s, flags=%04X", |
131 | macaddress.c_str(), fileid, filename.c_str(), filesize, | 130 | macaddress.c_str(), fileid, filename.c_str(), filesize, |
132 | filesignature.c_str(), encryption.c_str(), flags ); | 131 | filesignature.c_str(), encryption.c_str(), flags ); |
133 | #endif | 132 | #endif |
134 | eyekinfig_t eyekinfig(macaddress); | 133 | eyekinfig_t eyekinfig(macaddress); |
135 | 134 | ||
136 | umask(eyekinfig.get_umask()); | 135 | umask(eyekinfig.get_umask()); |
137 | 136 | ||
138 | std::string td = eyekinfig.get_targetdir(); | 137 | std::string td = eyekinfig.get_targetdir(); |
139 | tmpdir_t indir(td+"/.incoming.XXXXXX"); | 138 | tmpdir_t indir(td+"/.incoming.XXXXXX"); |
140 | 139 | ||
141 | std::string jf,lf; | 140 | std::string jf,lf; |
142 | binary_t digest, idigest; | 141 | binary_t digest, idigest; |
143 | 142 | ||
144 | for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { | 143 | for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { |
145 | #ifndef NDEBUG | 144 | #ifndef NDEBUG |
146 | syslog(LOG_DEBUG, | 145 | syslog(LOG_DEBUG, |
147 | " MIME attachment with id=%s, type=%s, size=%ld", | 146 | " MIME attachment with id=%s, type=%s, size=%ld", |
148 | (*i).id, (*i).type, (long)(*i).size ); | 147 | (*i).id, (*i).type, (long)(*i).size ); |
149 | #endif | 148 | #endif |
150 | 149 | ||
151 | if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) { | 150 | if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) { |
152 | std::string idigestr((*i).ptr,(*i).size); | 151 | std::string idigestr((*i).ptr,(*i).size); |
153 | #ifndef NDEBUG | 152 | #ifndef NDEBUG |
154 | syslog(LOG_DEBUG, " INTEGRITYDIGEST=%s", idigestr.c_str()); | 153 | syslog(LOG_DEBUG, " INTEGRITYDIGEST=%s", idigestr.c_str()); |
155 | #endif | 154 | #endif |
156 | idigest.from_hex(idigestr); | 155 | idigest.from_hex(idigestr); |
157 | } | 156 | } |
158 | if( (*i).id && !strcmp((*i).id,"FILENAME") ) { | 157 | if( (*i).id && !strcmp((*i).id,"FILENAME") ) { |
159 | assert( (*i).type && !strcmp((*i).type,"application/x-tar") ); | 158 | assert( (*i).type && !strcmp((*i).type,"application/x-tar") ); |
160 | #ifdef III_SAVE_TARS | 159 | #ifdef III_SAVE_TARS |
161 | std::string tarfile = indir.get_file(filename); | 160 | std::string tarfile = indir.get_file(filename); |
162 | { | 161 | { |
163 | std::ofstream(tarfile.c_str(),std::ios::out|std::ios::binary).write((*i).ptr,(*i).size); | 162 | std::ofstream(tarfile.c_str(),std::ios::out|std::ios::binary).write((*i).ptr,(*i).size); |
164 | } | 163 | } |
165 | #endif | 164 | #endif |
166 | 165 | ||
167 | if(!jf.empty()) throw std::runtime_error("already seen tarball"); | 166 | if(!jf.empty()) throw std::runtime_error("already seen tarball"); |
168 | if(!digest.empty()) throw std::runtime_error("already have integrity digest"); | 167 | if(!digest.empty()) throw std::runtime_error("already have integrity digest"); |
169 | digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key()); | 168 | digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key()); |
170 | #ifndef NDEBUG | 169 | #ifndef NDEBUG |
171 | syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str()); | 170 | syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str()); |
172 | #endif | 171 | #endif |
173 | 172 | ||
174 | tarchive_t a((*i).ptr,(*i).size); | 173 | tarchive_t a((*i).ptr,(*i).size); |
175 | while(a.read_next_header()) { | 174 | while(a.read_next_header()) { |
176 | std::string f = indir.get_file(a.entry_pathname()); | 175 | std::string f = indir.get_file(a.entry_pathname()); |
177 | std::string::size_type fl = f.length(); | 176 | std::string::size_type fl = f.length(); |
178 | if(fl<4) continue; | 177 | if(fl<4) continue; |
179 | const char *s = f.c_str()+fl-4; | 178 | const char *s = f.c_str()+fl-4; |
180 | if(!strcasecmp(s,".JPG")) | 179 | if(!strcasecmp(s,".JPG")) |
181 | jf = f; | 180 | jf = f; |
182 | else if(!strcasecmp(s,".log")) | 181 | else if(!strcasecmp(s,".log")) |
183 | lf = f; | 182 | lf = f; |
184 | else continue; | 183 | else continue; |
185 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); | 184 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); |
186 | if(fd<0) | 185 | if(fd<0) |
187 | throw std::runtime_error(gnu::autosprintf("failed to create output file '%s'",f.c_str())); | 186 | throw std::runtime_error(gnu::autosprintf("failed to create output file '%s'",f.c_str())); |
188 | if(!a.read_data_into_fd(fd)) | 187 | if(!a.read_data_into_fd(fd)) |
189 | throw std::runtime_error(gnu::autosprintf("failed to untar file into '%s'",f.c_str())); | 188 | throw std::runtime_error(gnu::autosprintf("failed to untar file into '%s'",f.c_str())); |
190 | close(fd); | 189 | close(fd); |
191 | } | 190 | } |
192 | } | 191 | } |
193 | } | 192 | } |
194 | 193 | ||
195 | if(jf.empty()) throw std::runtime_error("haven't seen jpeg file"); | 194 | if(jf.empty()) throw std::runtime_error("haven't seen jpeg file"); |
196 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); | 195 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); |
197 | 196 | ||
198 | std::string::size_type ls = jf.rfind('/'); | 197 | std::string::size_type ls = jf.rfind('/'); |
199 | // XXX: actually, lack of '/' signifies error here | 198 | // XXX: actually, lack of '/' signifies error here |
200 | std::string jbn = (ls==std::string::npos)?jf:jf.substr(ls+1); | 199 | std::string jbn = (ls==std::string::npos)?jf:jf.substr(ls+1); |
201 | ls = lf.rfind('/'); | 200 | ls = lf.rfind('/'); |