]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_dsi.c
change SIGHUP and SIGUSR1, SIGHUP reload config files, Volumes file are reloaded...
[netatalk.git] / etc / afpd / afp_dsi.c
index f4a1235bc5e50135c6fa876beb5ba7f67bfae1e5..1c1bc89bca80df4f2f3eb33aa7c13d9f9002ae69 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_dsi.c,v 1.22 2002-08-22 06:59:07 jmarcus Exp $
+ * $Id: afp_dsi.c,v 1.27.2.1 2003-05-26 11:17:25 didg Exp $
  *
  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
 #include "auth.h"
 #include "fork.h"
 
+#ifdef FORCE_UIDGID
+#warning UIDGID
+#include "uid.h"
+#endif /* FORCE_UIDGID */
+
 extern struct oforks   *writtenfork;
 
 #define CHILD_DIE         (1 << 0)
@@ -66,7 +71,10 @@ static __inline__ void afp_dsi_close(AFPObj *obj)
     dsi_close(dsi);
 }
 
-/* a little bit of code duplication. */
+/* -------------------------------
+ * SIGTERM
+ * a little bit of code duplication. 
+ */
 static void afp_dsi_die(int sig)
 {
     dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN);
@@ -82,6 +90,9 @@ static void afp_dsi_die(int sig)
     }
 }
 
+/* ---------------------------------
+ * SIGUSR1 down in five mn.
+*/
 static void afp_dsi_timedown()
 {
     struct sigaction   sv;
@@ -97,11 +108,11 @@ static void afp_dsi_timedown()
     it.it_interval.tv_usec = 0;
     it.it_value.tv_sec = 300;
     it.it_value.tv_usec = 0;
+
     if ( setitimer( ITIMER_REAL, &it, 0 ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_timedown: setitimer: %s", strerror(errno) );
         afp_dsi_die(1);
     }
-
     memset(&sv, 0, sizeof(sv));
     sv.sa_handler = afp_dsi_die;
     sigemptyset( &sv.sa_mask );
@@ -112,8 +123,30 @@ static void afp_dsi_timedown()
         LOG(log_error, logtype_afpd, "afp_timedown: sigaction: %s", strerror(errno) );
         afp_dsi_die(1);
     }
+
+    /* ignore myself */
+    sv.sa_handler = SIG_IGN;
+    sigemptyset( &sv.sa_mask );
+    sv.sa_flags = SA_RESTART;
+    if ( sigaction( SIGUSR1, &sv, 0 ) < 0 ) {
+        LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGHUP: %s", strerror(errno) );
+        afp_dsi_die(1);
+    }
+
 }
 
+/* ---------------------------------
+ * SIGHUP reload configuration file
+ * FIXME here or we wait ?
+*/
+volatile reload_request = 0;
+
+static void afp_dsi_reload()
+{
+    reload_request = 1;
+}
+
+/* ---------------------- */
 #ifdef SERVERTEXT
 static void afp_dsi_getmesg (int sig)
 {
@@ -122,12 +155,18 @@ static void afp_dsi_getmesg (int sig)
 }
 #endif /* SERVERTEXT */
 
+/* ---------------------- */
 static void alarm_handler()
 {
+int err;
     /* if we're in the midst of processing something,
        don't die. */
     if ((child.flags & CHILD_RUNNING) || (child.tickle++ < child.obj->options.timeout)) {
-        dsi_tickle(child.obj->handle);
+        if (!(err = pollvoltime(child.obj)))
+            err = dsi_tickle(child.obj->handle);
+        if (err <= 0) 
+            afp_dsi_die(1);
+        
     } else { /* didn't receive a tickle. close connection */
         LOG(log_error, logtype_afpd, "afp_alarm: child timed out");
         afp_dsi_die(1);
@@ -135,23 +174,24 @@ static void alarm_handler()
 }
 
 
-/*
- *  Signal handler for SIGUSR1 - set the debug flag and 
+/*  ---------------------------------
+ *  old signal handler for SIGUSR1 - set the debug flag and 
  *  redirect stdout to <tmpdir>/afpd-debug-<pid>.
  */
 void afp_set_debug (int sig)
 {
     char       fname[MAXPATHLEN];
 
-    strncpy(fname, tempnam(P_tmpdir, "afpd-debug"), MAXPATHLEN-1);
+    snprintf(fname, MAXPATHLEN-1, "%safpd-debug-%d", P_tmpdir, getpid());
     freopen(fname, "w", stdout);
     child.obj->options.flags |= OPTION_DEBUG;
 
     return;
 }
 
-
-/* afp over dsi. this never returns. */
+/* -------------------------------------------
+ afp over dsi. this never returns. 
+*/
 void afp_over_dsi(AFPObj *obj)
 {
     DSI *dsi = (DSI *) obj->handle;
@@ -166,22 +206,26 @@ void afp_over_dsi(AFPObj *obj)
     child.obj = obj;
     child.tickle = child.flags = 0;
 
-    /* install SIGTERM and SIGHUP */
     memset(&action, 0, sizeof(action));
-    action.sa_handler = afp_dsi_timedown;
+
+    /* install SIGHUP */
+    action.sa_handler = afp_dsi_reload;
     sigemptyset( &action.sa_mask );
     sigaddset(&action.sa_mask, SIGALRM);
     sigaddset(&action.sa_mask, SIGTERM);
+    sigaddset(&action.sa_mask, SIGUSR1);
     action.sa_flags = SA_RESTART;
     if ( sigaction( SIGHUP, &action, 0 ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
         afp_dsi_die(1);
     }
 
+    /* install SIGTERM */
     action.sa_handler = afp_dsi_die;
     sigemptyset( &action.sa_mask );
     sigaddset(&action.sa_mask, SIGALRM);
     sigaddset(&action.sa_mask, SIGHUP);
+    sigaddset(&action.sa_mask, SIGUSR1);
     action.sa_flags = SA_RESTART;
     if ( sigaction( SIGTERM, &action, 0 ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
@@ -200,10 +244,12 @@ void afp_over_dsi(AFPObj *obj)
     }
 #endif /* SERVERTEXT */
 
-    /*  SIGUSR1 - set "debug" flag on this process.  */
-    action.sa_handler = afp_set_debug;
+    /*  SIGUSR1 - set down in 5 minutes  */
+    action.sa_handler = afp_dsi_timedown;
     sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGUSR1);
+    sigaddset(&action.sa_mask, SIGALRM);
+    sigaddset(&action.sa_mask, SIGHUP);
+    sigaddset(&action.sa_mask, SIGTERM);
     action.sa_flags = SA_RESTART;
     if ( sigaction( SIGUSR1, &action, 0) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
@@ -224,15 +270,20 @@ void afp_over_dsi(AFPObj *obj)
     /* get stuck here until the end */
     while ((cmd = dsi_receive(dsi))) {
         child.tickle = 0;
+        dsi_sleep(dsi, 0); /* wake up */
+        if (reload_request) {
+            reload_request = 0;
+            load_volumes(child.obj);
+        }
 
         if (cmd == DSIFUNC_TICKLE) {
             /* so we don't get killed on the client side. */
             if (child.flags & CHILD_DIE)
                 dsi_tickle(dsi);
             continue;
-        } else if (!(child.flags & CHILD_DIE)) /* reset tickle timer */
+        } else if (!(child.flags & CHILD_DIE)) /* reset tickle timer */
             setitimer(ITIMER_REAL, &dsi->timer, NULL);
-
+        }
         switch(cmd) {
         case DSIFUNC_CLOSE:
             afp_dsi_close(obj);
@@ -263,9 +314,15 @@ void afp_over_dsi(AFPObj *obj)
             if (afp_switch[function]) {
                 dsi->datalen = DSI_DATASIZ;
                 child.flags |= CHILD_RUNNING;
+
                 err = (*afp_switch[function])(obj,
                                               dsi->commands, dsi->cmdlen,
                                               dsi->data, &dsi->datalen);
+#ifdef FORCE_UIDGID
+               /* bring everything back to old euid, egid */
+               if (obj->force_uid)
+                   restore_uidgid ( &obj->uidgid );
+#endif /* FORCE_UIDGID */
                 child.flags &= ~CHILD_RUNNING;
             } else {
                 LOG(log_error, logtype_afpd, "bad function %X", function);
@@ -303,6 +360,11 @@ void afp_over_dsi(AFPObj *obj)
                 err = (*afp_switch[function])(obj, dsi->commands, dsi->cmdlen,
                                               dsi->data, &dsi->datalen);
                 child.flags &= ~CHILD_RUNNING;
+#ifdef FORCE_UIDGID
+               /* bring everything back to old euid, egid */
+               if (obj->force_uid)
+                   restore_uidgid ( &obj->uidgid );
+#endif /* FORCE_UIDGID */
             } else {
                 LOG(log_error, logtype_afpd, "(write) bad function %x", function);
                 dsi->datalen = 0;