diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/aconfig.h.in | 299 | ||||
-rw-r--r-- | src/config.h | 2 | ||||
-rw-r--r-- | src/main.c | 13 | ||||
-rw-r--r-- | src/ui.c | 2 | ||||
-rw-r--r-- | src/ui_elements.c | 11 | ||||
-rw-r--r-- | src/ui_ipc.c | 30 | ||||
-rw-r--r-- | src/ui_ipc.h | 9 | ||||
-rw-r--r-- | tests/mqtest.c | 23 |
10 files changed, 363 insertions, 30 deletions
diff --git a/Makefile.am b/Makefile.am index d682608..1d76541 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,6 @@ clean-local: distclean-local: clean-local rm -f aclocal.m4 config.log config.status configure - rm -f Makefile.in src/Makefile.in src/aconfig.h.in src/aconfig.h.in~ src/*.d + rm -f Makefile.in src/Makefile.in src/aconfig.h.in~ src/*.d rm -rf build autom4te.cache diff --git a/configure.ac b/configure.ac index 3786c0e..943f5cf 100644 --- a/configure.ac +++ b/configure.ac @@ -34,7 +34,7 @@ AC_HEADER_STDC AC_HEADER_STAT AC_HEADER_DIRENT AC_HEADER_ASSERT -AC_CHECK_HEADERS([stdio.h stdlib.h stdbool.h string.h unistd.h errno.h sys/stat.h sys/types.h sys/wait.h fcntl.h semaphore.h time.h mqueue.h]) +AC_CHECK_HEADERS([stdio.h stdlib.h stdbool.h string.h unistd.h errno.h sys/stat.h sys/types.h sys/wait.h fcntl.h semaphore.h time.h mqueue.h alloca.h]) # Checks for typedefs, structures, and compiler characteristics. AC_COMPUTE_INT diff --git a/src/aconfig.h.in b/src/aconfig.h.in new file mode 100644 index 0000000..f690396 --- /dev/null +++ b/src/aconfig.h.in @@ -0,0 +1,299 @@ +/* src/aconfig.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `alarm' function. */ +#undef HAVE_ALARM + +/* Define to 1 if you have the <alloca.h> header file. */ +#undef HAVE_ALLOCA_H + +/* Define to 1 if you have the `asprintf' function. */ +#undef HAVE_ASPRINTF + +/* Define to 1 if you have the `clock_gettime' function. */ +#undef HAVE_CLOCK_GETTIME + +/* Define to 1 if you have the `close' function. */ +#undef HAVE_CLOSE + +/* Do NOT change THIS! */ +#undef HAVE_CONFIG + +/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'. + */ +#undef HAVE_DIRENT_H + +/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ +#undef HAVE_DOPRNT + +/* Define to 1 if you have the <errno.h> header file. */ +#undef HAVE_ERRNO_H + +/* Define to 1 if you have the <fcntl.h> header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `fork' function. */ +#undef HAVE_FORK + +/* Define to 1 if you have the `fprintf' function. */ +#undef HAVE_FPRINTF + +/* Define to 1 if you have the `getpagesize' function. */ +#undef HAVE_GETPAGESIZE + +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#undef HAVE_MALLOC + +/* Define to 1 if you have the `memcpy' function. */ +#undef HAVE_MEMCPY + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if you have the `mkfifo' function. */ +#undef HAVE_MKFIFO + +/* Define to 1 if you have a working `mmap' system call. */ +#undef HAVE_MMAP + +/* Define to 1 if you have the <mqueue.h> header file. */ +#undef HAVE_MQUEUE_H + +/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */ +#undef HAVE_NDIR_H + +/* Define to 1 if you have the `open' function. */ +#undef HAVE_OPEN + +/* Define to 1 if you have the `printf' function. */ +#undef HAVE_PRINTF + +/* Define to 1 if your system has a GNU libc compatible `realloc' function, + and to 0 otherwise. */ +#undef HAVE_REALLOC + +/* Define to 1 if you have the <semaphore.h> header file. */ +#undef HAVE_SEMAPHORE_H + +/* Define to 1 if you have the `stat' function. */ +#undef HAVE_STAT + +/* Define to 1 if `stat' has the bug that it succeeds when given the + zero-length file name argument. */ +#undef HAVE_STAT_EMPTY_STRING_BUG + +/* Define to 1 if you have the <stdbool.h> header file. */ +#undef HAVE_STDBOOL_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdio.h> header file. */ +#undef HAVE_STDIO_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strdup' function. */ +#undef HAVE_STRDUP + +/* Define to 1 if you have the `strerror' function. */ +#undef HAVE_STRERROR + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strlen' function. */ +#undef HAVE_STRLEN + +/* Define to 1 if you have the `strndup' function. */ +#undef HAVE_STRNDUP + +/* Define to 1 if you have the `strnlen' function. */ +#undef HAVE_STRNLEN + +/* Define to 1 if you have the `strstr' function. */ +#undef HAVE_STRSTR + +/* Define to 1 if you have the `strtol' function. */ +#undef HAVE_STRTOL + +/* Define to 1 if you have the `system' function. */ +#undef HAVE_SYSTEM + +/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'. + */ +#undef HAVE_SYS_DIR_H + +/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'. + */ +#undef HAVE_SYS_NDIR_H + +/* Define to 1 if you have the <sys/param.h> header file. */ +#undef HAVE_SYS_PARAM_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/time.h> header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <sys/wait.h> header file. */ +#undef HAVE_SYS_WAIT_H + +/* Define to 1 if you have the <time.h> header file. */ +#undef HAVE_TIME_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the `vfork' function. */ +#undef HAVE_VFORK + +/* Define to 1 if you have the <vfork.h> header file. */ +#undef HAVE_VFORK_H + +/* Define to 1 if you have the `vprintf' function. */ +#undef HAVE_VPRINTF + +/* Define to 1 if `fork' works. */ +#undef HAVE_WORKING_FORK + +/* Define to 1 if `vfork' works. */ +#undef HAVE_WORKING_VFORK + +/* Define to 1 if the system has the type `_Bool'. */ +#undef HAVE__BOOL + +/* Define to 1 if `lstat' dereferences a symlink specified with a trailing + slash. */ +#undef LSTAT_FOLLOWS_SLASHED_SYMLINK + +/* Define to 1 if assertions should be disabled. */ +#undef NDEBUG + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */ +#undef STAT_MACROS_BROKEN + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ +#undef TIME_WITH_SYS_TIME + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif + + +/* Define if using the dmalloc debugging malloc package */ +#undef WITH_DMALLOC + +/* Define to 1 if on MINIX. */ +#undef _MINIX + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#undef _POSIX_1_SOURCE + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#undef _POSIX_SOURCE + +/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>, + <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT8_T + +/* Define to `int' if <sys/types.h> doesn't define. */ +#undef gid_t + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to rpl_malloc if the replacement function should be used. */ +#undef malloc + +/* Define to `int' if <sys/types.h> does not define. */ +#undef mode_t + +/* Define to `int' if <sys/types.h> does not define. */ +#undef pid_t + +/* Define to rpl_realloc if the replacement function should be used. */ +#undef realloc + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +#undef size_t + +/* Define to `int' if <sys/types.h> does not define. */ +#undef ssize_t + +/* Define to `int' if <sys/types.h> doesn't define. */ +#undef uid_t + +/* Define to the type of an unsigned integer type of width exactly 16 bits if + such a type exists and the standard includes do not define it. */ +#undef uint16_t + +/* Define to the type of an unsigned integer type of width exactly 8 bits if + such a type exists and the standard includes do not define it. */ +#undef uint8_t + +/* Define as `fork' if `vfork' does not work. */ +#undef vfork diff --git a/src/config.h b/src/config.h index a7fddc0..9d72ef3 100644 --- a/src/config.h +++ b/src/config.h @@ -12,8 +12,6 @@ #define MSQ_PWD "/naskpass-passwd" #define MSQ_INF "/naskpass-info" -#define IPC_MQSIZ 128 - #ifdef _VERSION #define VERSION _VERSION #else @@ -142,21 +142,22 @@ main(int argc, char **argv) while ( ui_ipc_getvalue(SEM_UI) > 0 || ui_ipc_getvalue(SEM_IN) > 0 ) { ui_ipc_sempost(SEM_BS); if (read(ffd, pbuf, IPC_MQSIZ) >= 0) { - ui_ipc_msgsend(MQ_IF, MSG(MSG_BUSY_FD), strlen(MSG(MSG_BUSY_FD))); + ui_ipc_msgsend(MQ_IF, MSG(MSG_BUSY_FD)); if (run_cryptcreate(pbuf, GETOPT(CRYPT_CMD).str) != 0) { - ui_ipc_msgsend(MQ_IF, MSG(MSG_CRYPTCMD_ERR), strlen(MSG(MSG_CRYPTCMD_ERR))); + ui_ipc_msgsend(MQ_IF, MSG(MSG_CRYPTCMD_ERR)); } - } else if ( ui_ipc_msgrecv(MQ_PW, pbuf, IPC_MQSIZ) != (int)-1 ) { - ui_ipc_msgsend(MQ_IF, MSG(MSG_BUSY), strlen(MSG(MSG_BUSY))); + } else if ( ui_ipc_msgcount(MQ_PW) > 0 ) { + ui_ipc_msgrecv(MQ_PW, pbuf); + ui_ipc_msgsend(MQ_IF, MSG(MSG_BUSY)); if (run_cryptcreate(pbuf, GETOPT(CRYPT_CMD).str) != 0) { - ui_ipc_msgsend(MQ_IF, MSG(MSG_CRYPTCMD_ERR), strlen(MSG(MSG_CRYPTCMD_ERR))); + ui_ipc_msgsend(MQ_IF, MSG(MSG_CRYPTCMD_ERR)); } ui_ipc_semwait(SEM_IN); } ui_ipc_semwait(SEM_BS); usleep(100000); waitpid(child, &c_status, WNOHANG); - if ( WIFSIGNALED(c_status) != 0 ) { + if ( WIFEXITED(c_status) != 0 ) { break; } } @@ -203,7 +203,7 @@ ui_thrd(void *arg) pthread_mutex_lock(&mtx_update); while ( ui_ipc_getvalue(SEM_UI) > 0 ) { cnd_ret = pthread_cond_timedwait(&cnd_update, &mtx_update, &wait); - if (--atmout == 0) ui_ipc_semtrywait(SEM_UI); + if (--atmout <= 0) ui_ipc_semtrywait(SEM_UI); pthread_mutex_lock(&mtx_busy); do_ui_update( (cnd_ret == ETIMEDOUT ? true : false) ); pthread_mutex_unlock(&mtx_busy); diff --git a/src/ui_elements.c b/src/ui_elements.c index 27ccea0..b274529 100644 --- a/src/ui_elements.c +++ b/src/ui_elements.c @@ -58,12 +58,12 @@ infownd_update(WINDOW *win, struct txtwindow *tw) } static int -mq_passwd_send(char *passwd, size_t len) +mq_passwd_send(char *passwd) { int ret; ui_ipc_sempost(SEM_IN); - ret = ui_ipc_msgsend(MQ_PW, passwd, len); + ret = ui_ipc_msgsend(MQ_PW, passwd); return ret; } @@ -71,14 +71,17 @@ static int passwd_input_cb(WINDOW *wnd, void *data, int key) { struct input *a = (struct input *) data; + char ipc_buf[IPC_MQSIZ+1]; + memset(ipc_buf, '\0', IPC_MQSIZ+1); switch (key) { case UIKEY_ENTER: deactivate_input(pw_input); - mq_passwd_send(a->input, a->input_len); + mq_passwd_send(a->input); clear_input(wnd, a); + ui_ipc_msgrecv(MQ_IF, ipc_buf); set_txtwindow_title(infownd, "BUSY"); - set_txtwindow_text(infownd, "BLA"); + set_txtwindow_text(infownd, ipc_buf); set_txtwindow_active(infownd, true); break; case UIKEY_BACKSPACE: diff --git a/src/ui_ipc.c b/src/ui_ipc.c index 9eac79e..cf137e7 100644 --- a/src/ui_ipc.c +++ b/src/ui_ipc.c @@ -1,12 +1,13 @@ #include <stdio.h> #include <stdlib.h> -#include <strings.h> +#include <string.h> #ifdef SEM_TIMEDWAIT #include <time.h> #endif #include <semaphore.h> #include <mqueue.h> #include <sys/stat.h> +#include <alloca.h> #include <errno.h> #include "ui_ipc.h" @@ -35,14 +36,14 @@ ui_ipc_init(int is_master) sp_oflags = O_CREAT | O_EXCL; mq_oflags = O_NONBLOCK | O_CREAT | O_EXCL; crt_flags = S_IRUSR | S_IWUSR; - JMP_IF( msqs[MQ_PW] = mq_open(MSQ_PWD, mq_oflags | O_RDONLY, crt_flags, &m_attr), (mqd_t)-1, error ); - JMP_IF( msqs[MQ_IF] = mq_open(MSQ_INF, mq_oflags | O_WRONLY, crt_flags, &m_attr), (mqd_t)-1, error ); + JMP_IF( msqs[MQ_PW] = mq_open(MSQ_PWD, mq_oflags | O_RDONLY, crt_flags, &m_attr), (mqd_t)-1, error ); + JMP_IF( msqs[MQ_IF] = mq_open(MSQ_INF, mq_oflags | O_WRONLY, crt_flags, &m_attr), (mqd_t)-1, error ); } else { sp_oflags = 0; mq_oflags = 0; crt_flags = 0; - JMP_IF( msqs[MQ_PW] = mq_open(MSQ_PWD, mq_oflags | O_WRONLY, crt_flags, &m_attr), (mqd_t)-1, error ); - JMP_IF( msqs[MQ_IF] = mq_open(MSQ_INF, mq_oflags | O_RDONLY, crt_flags, &m_attr), (mqd_t)-1, error ); + JMP_IF( msqs[MQ_PW] = mq_open(MSQ_PWD, mq_oflags | O_WRONLY, crt_flags, &m_attr), (mqd_t)-1, error ); + JMP_IF( msqs[MQ_IF] = mq_open(MSQ_INF, mq_oflags | O_RDONLY, crt_flags, &m_attr), (mqd_t)-1, error ); } JMP_IF( sems[SEM_UI] = sem_open(SEM_GUI, sp_oflags, crt_flags, 0), SEM_FAILED, error ); JMP_IF( sems[SEM_IN] = sem_open(SEM_INP, sp_oflags, crt_flags, 0), SEM_FAILED, error ); @@ -117,14 +118,25 @@ ui_ipc_semtimedwait(enum UI_IPC_SEM e_sp, int timeout) #endif int -ui_ipc_msgsend(enum UI_IPC_MSQ e_mq, const char *msg_ptr, size_t msg_len) +ui_ipc_msgsend(enum UI_IPC_MSQ e_mq, const char *msg_ptr) { - return ( mq_send(msqs[e_mq], msg_ptr, msg_len, 0) ); + char *tmp = alloca(IPC_MQSIZ); + memset(tmp, '\0', IPC_MQSIZ); + strncpy(tmp, msg_ptr, IPC_MQSIZ); + return ( mq_send(msqs[e_mq], tmp, IPC_MQSIZ, 0) ); } ssize_t -ui_ipc_msgrecv(enum UI_IPC_MSQ e_mq, char *msg_ptr, size_t msg_len) +ui_ipc_msgrecv(enum UI_IPC_MSQ e_mq, char *msg_ptr) { - return ( mq_receive(msqs[e_mq], msg_ptr, msg_len, NULL) ); + return mq_receive(msqs[e_mq], msg_ptr, IPC_MQSIZ, NULL); } +long +ui_ipc_msgcount(enum UI_IPC_MSQ e_mq) +{ + struct mq_attr m_attr; + bzero(&m_attr, sizeof(struct mq_attr)); + if (mq_getattr(msqs[e_mq], &m_attr) != 0) return -1; + return m_attr.mq_curmsgs; +} diff --git a/src/ui_ipc.h b/src/ui_ipc.h index 2c5bcb5..ec36f35 100644 --- a/src/ui_ipc.h +++ b/src/ui_ipc.h @@ -4,6 +4,8 @@ #include "status.h" #include "config.h" +#define IPC_MQSIZ 128 + enum UI_IPC_SEM { SEM_RD = 0, /* UI Init done? */ @@ -44,9 +46,12 @@ ui_ipc_semtimedwait(enum UI_IPC_MSQ e_sp, int timeout); #endif int -ui_ipc_msgsend(enum UI_IPC_MSQ e_mq, const char *msg_ptr, size_t msg_len); +ui_ipc_msgsend(enum UI_IPC_MSQ e_mq, const char *msg_ptr); ssize_t -ui_ipc_msgrecv(enum UI_IPC_MSQ e_mq, char *msg_ptr, size_t msg_len); +ui_ipc_msgrecv(enum UI_IPC_MSQ e_mq, char *msg_ptr); + +long +ui_ipc_msgcount(enum UI_IPC_MSQ e_mq); #endif diff --git a/tests/mqtest.c b/tests/mqtest.c index e9bc8e7..f2808c8 100644 --- a/tests/mqtest.c +++ b/tests/mqtest.c @@ -1,18 +1,22 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include <string.h> #include <fcntl.h> #include <sys/stat.h> +#include <sys/wait.h> #include <mqueue.h> #include <assert.h> static mqd_t mq_test; +static mqd_t mq_recv; static const size_t bufsiz = 256; int main(int argc, char **argv) { + int c_stat; struct mq_attr m_attr; char buf[bufsiz], recv[bufsiz]; unsigned int prio; @@ -31,10 +35,10 @@ int main(int argc, char **argv) mq_unlink("/testmq"); assert( (mq_test = mq_open( "/testmq", O_NONBLOCK | O_CREAT | O_EXCL | O_RDWR, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1 ); assert( mq_getattr(mq_test, &m_attr) == 0 ); - printf("flags.........: %ld\n" - "maxmsg........: %ld\n" - "msgsize.......: %ld\n" - "curmsg........: %ld\n", + printf("flags..........: %ld\n" + "maxmsg.........: %ld\n" + "msgsize........: %ld\n" + "curmsg.........: %ld\n", m_attr.mq_flags, m_attr.mq_maxmsg, m_attr.mq_msgsize, m_attr.mq_curmsgs); strcpy(buf, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVQXYZ"); @@ -44,6 +48,17 @@ int main(int argc, char **argv) printf("SENT(%03lu bytes): %s\n", (long unsigned int) strlen(buf), buf); printf("RECV(%03lu bytes): %s\n", (long unsigned int) sz_recv, recv); + memset(recv, '\0', bufsiz); + if (fork() > 0) { + assert( (mq_recv = mq_open( "/testmq", O_RDONLY, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1 ); + assert ( (sz_recv = mq_receive(mq_recv, recv, bufsiz, &prio)) > 0 ); + printf("RECV(%03lu bytes): %s\n", (long unsigned int) sz_recv, recv); + return 0; + } + printf("SENT(%03lu bytes): %s\n", (long unsigned int) strlen(buf), buf); + assert ( mq_send(mq_test, buf, bufsiz, 0) == 0 ); + wait(&c_stat); + return 0; } |