From: Thibault Godouet Date: Mon, 5 Jun 2006 20:02:55 +0000 (+0000) Subject: Use sockaddr's field sa_len/sun_len on system defining it (BSD, ...) X-Git-Tag: ver3_0_2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3b93b211c3a9b9381cad92335edf545aaf442c5;p=thirdparty%2Ffcron.git Use sockaddr's field sa_len/sun_len on system defining it (BSD, ...) --- diff --git a/config.h.in b/config.h.in index 57103af..d40a71b 100644 --- a/config.h.in +++ b/config.h.in @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: config.h.in,v 1.57 2006-05-20 16:27:43 thib Exp $ */ + /* $Id: config.h.in,v 1.58 2006-06-05 20:03:05 thib Exp $ */ /* *********************************************************** */ @@ -265,6 +265,9 @@ /* Define if you have the putenv function. */ #undef HAVE_PUTENV +/* Define if (struct sockaddr) has an sa_len field. */ +#undef HAVE_SA_LEN + /* Define if you have the setenv function. */ #undef HAVE_SETENV diff --git a/configure.in b/configure.in index c6c1389..4bef3b3 100644 --- a/configure.in +++ b/configure.in @@ -127,6 +127,16 @@ if test "$crypt" -eq "1"; then fi +dnl Check for post-Reno style struct sockaddr +AC_CACHE_CHECK([for sa_len], + ac_cv_sa_len, +[AC_TRY_COMPILE([#include +#include ], [int main(void) { + struct sockaddr t;t.sa_len = 0;}], + ac_cv_sa_len=yes,ac_cv_sa_len=no)]) +if test $ac_cv_sa_len = yes; then + AC_DEFINE(HAVE_SA_LEN) +fi dnl --------------------------------------------------------------------- dnl Check for fcron more specific stuffs (paths, progs, ...) diff --git a/fcrontab.c b/fcrontab.c index 1aa5605..13355d9 100644 --- a/fcrontab.c +++ b/fcrontab.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fcrontab.c,v 1.69 2006-05-20 16:26:37 thib Exp $ */ + /* $Id: fcrontab.c,v 1.70 2006-06-05 20:02:55 thib Exp $ */ /* * The goal of this program is simple : giving a user interface to fcron @@ -46,7 +46,7 @@ #include "temp_file.h" #include "read_string.h" -char rcs_info[] = "$Id: fcrontab.c,v 1.69 2006-05-20 16:26:37 thib Exp $"; +char rcs_info[] = "$Id: fcrontab.c,v 1.70 2006-06-05 20:02:55 thib Exp $"; void info(void); void usage(void); @@ -1021,6 +1021,10 @@ main(int argc, char **argv) /* Open PAM session for the user and obtain any security credentials we might need */ +#ifdef USE_SETE_ID + if (seteuid(uid) != 0) + die_e("Could not change euid to %d", uid); +#endif debug("username: %s", user); retcode = pam_start("fcrontab", user, &apamconv, &pamh); if (retcode != PAM_SUCCESS) die_pame(pamh, retcode, "Could not start PAM"); @@ -1044,6 +1048,10 @@ main(int argc, char **argv) /* Close the log here, because PAM calls openlog(3) and our log messages could go to the wrong facility */ xcloselog(); +#ifdef USE_SETE_ID + if (seteuid(fcrontab_uid) != 0) + die_e("Couldn't change euid to fcrontab_uid[%d]",fcrontab_uid); +#endif #endif /* USE_PAM */ if (uid != fcrontab_uid) diff --git a/socket.c b/socket.c index 38f1c6a..a81eac3 100644 --- a/socket.c +++ b/socket.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: socket.c,v 1.19 2006-01-11 00:58:21 thib Exp $ */ + /* $Id: socket.c,v 1.20 2006-06-05 20:03:08 thib Exp $ */ /* This file contains all fcron's code (server) to handle communication with fcrondyn */ @@ -134,6 +134,7 @@ init_socket(void) { struct sockaddr_un addr; int len = 0; + int sun_len = 0; /* used in fcron.c:main_loop():select() */ FD_ZERO(&read_set); @@ -145,15 +146,20 @@ init_socket(void) } addr.sun_family = AF_UNIX; - if ( (len = strlen(fifofile)) > sizeof(addr.sun_path) ) { - error("Error : fifo file path too long (max is %d)", sizeof(addr.sun_path)); + len = strlen(fifofile); + if ( len > sizeof(addr.sun_path) - 1 ) { + error("Error : fifo file path too long (max is %d)", sizeof(addr.sun_path) - 1); goto err; } - strncpy(addr.sun_path, fifofile, sizeof(addr.sun_path) - 1); + strncpy(addr.sun_path, fifofile, sizeof(addr.sun_path)); addr.sun_path[sizeof(addr.sun_path) -1 ] = '\0'; + sun_len = (addr.sun_path - (char *)&addr) + len; +#if HAVE_SA_LEN + addr.sun_len = sun_len; +#endif unlink(fifofile); - if (bind(listen_fd, (struct sockaddr*) &addr, sizeof(addr.sun_family)+len+1) != 0){ + if (bind(listen_fd, (struct sockaddr*) &addr, sun_len) != 0){ error_e("Cannot bind socket to '%s'", fifofile); goto err; }