]> git.ipfire.org Git - thirdparty/fcron.git/commitdiff
Use sockaddr's field sa_len/sun_len on system defining it (BSD, ...)
authorThibault Godouet <yo8192@users.noreply.github.com>
Mon, 5 Jun 2006 20:02:55 +0000 (20:02 +0000)
committerThibault Godouet <yo8192@users.noreply.github.com>
Mon, 5 Jun 2006 20:02:55 +0000 (20:02 +0000)
config.h.in
configure.in
fcrontab.c
socket.c

index 57103af858839f74d91520bc43a2d0d50b9dfacc..d40a71b7b0f4674bb70851c275a85bb3e8865d45 100644 (file)
@@ -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 $ */
 
 
 /* *********************************************************** */
 /* 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
 
index c6c1389bd90568cf0e05c22ee21a5c22ee70fcd5..4bef3b359d6cadda9b8eb74741bbc758f9044e24 100644 (file)
@@ -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 <sys/types.h>
+#include <sys/socket.h>], [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, ...)
index 1aa5605e6ed9eb0d73b82e5b3a69cf016a805d26..13355d9b6384dd01f4ebe7de9d37902388543988 100644 (file)
@@ -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)
index 38f1c6af51d6d218e2fdc0e8e24f97eb722dc101..a81eac3a2df229a7efac3773589495f5e107da0b 100644 (file)
--- 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;
     }