]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_dsi.c
don't create an adouble file in ad_metadata for noadouble volume
[netatalk.git] / etc / afpd / afp_dsi.c
index 9b0baaad042ddebd193e7a867bba3d9d49c7ceb6..9fc2beb970b383ce1f1b65f1bb9d21313f331164 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_dsi.c,v 1.43 2009-10-22 05:53:20 didg Exp $
+ * $Id: afp_dsi.c,v 1.48 2009-11-14 05:18:50 didg Exp $
  *
  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
@@ -46,6 +46,7 @@
 #define CHILD_DIE         (1 << 0)
 #define CHILD_RUNNING     (1 << 1)
 #define CHILD_SLEEPING    (1 << 2)
+#define CHILD_DATA        (1 << 3)
 
 static struct {
     AFPObj *obj;
@@ -58,6 +59,14 @@ static void afp_dsi_close(AFPObj *obj)
 {
     DSI *dsi = obj->handle;
 
+    /* we may have been called from a signal handler caught when afpd was running
+     * as uid 0, that's the wrong user for volume's prexec_close scripts if any,
+     * restore our login user
+     */
+    if (seteuid( obj->uid ) < 0) {
+        LOG(log_error, logtype_afpd, "can't seteuid back %s", strerror(errno));
+        exit(EXITERR_SYS);
+    }
     close_all_vol();
     if (obj->logout)
         (*obj->logout)();
@@ -114,8 +123,11 @@ static void afp_dsi_timedown(int sig _U_)
     child.flags |= CHILD_DIE;
     /* shutdown and don't reconnect. server going down in 5 minutes. */
     setmessage("The server is going down for maintenance.");
-    dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT |
-                  AFPATTN_MESG | AFPATTN_TIME(5));
+    if (dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT |
+                  AFPATTN_MESG | AFPATTN_TIME(5)) < 0) {
+        DSI *dsi = (DSI *) child.obj->handle;
+        dsi->down_request = 1;
+    }                  
 
     it.it_interval.tv_sec = 0;
     it.it_interval.tv_usec = 0;
@@ -145,7 +157,6 @@ static void afp_dsi_timedown(int sig _U_)
         LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGHUP: %s", strerror(errno) );
         afp_dsi_die(EXITERR_SYS);
     }
-
 }
 
 /* ---------------------------------
@@ -166,7 +177,8 @@ static void afp_dsi_getmesg (int sig _U_)
     DSI *dsi = (DSI *) child.obj->handle;
 
     dsi->msg_request = 1;
-    dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5));
+    if (dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5)) < 0)
+        dsi->msg_request = 2;
 }
 #endif /* SERVERTEXT */
 
@@ -179,6 +191,13 @@ static void alarm_handler(int sig _U_)
      * may use alarm() */
     setitimer(ITIMER_REAL, &dsi->timer, NULL);
 
+    /* we got some traffic from the client since the previous timer 
+     * tick. */
+    if ((child.flags & CHILD_DATA)) {
+        child.flags &= ~CHILD_DATA;
+        return;
+    }
+
     /* if we're in the midst of processing something,
        don't die. */
     if ((child.flags & CHILD_SLEEPING) && child.tickle++ < child.obj->options.sleep) {
@@ -207,9 +226,18 @@ static void pending_request(DSI *dsi)
 
     /* read msg if any, it could be done in afp_getsrvrmesg */
     if (dsi->msg_request) {
+        if (dsi->msg_request == 2) {
+            /* didn't send it in signal handler */
+            dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5));
+        }
         dsi->msg_request = 0;
         readmessage(child.obj);
     }
+    if (dsi->down_request) {
+        dsi->down_request = 0;
+        dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT |
+                  AFPATTN_MESG | AFPATTN_TIME(5));
+    }
 }
 
 /* -------------------------------------------
@@ -221,7 +249,6 @@ void afp_over_dsi(AFPObj *obj)
     u_int32_t err, cmd;
     u_int8_t function;
     struct sigaction action;
-    const char *afpcmpstr;
 
     obj->exit = afp_dsi_die;
     obj->reply = (int (*)()) dsi_cmdreply;
@@ -327,6 +354,8 @@ void afp_over_dsi(AFPObj *obj)
             pending_request(dsi);
             continue;
         } 
+
+        child.flags |= CHILD_DATA;
         switch(cmd) {
         case DSIFUNC_CLOSE:
             afp_dsi_close(obj);
@@ -352,14 +381,13 @@ void afp_over_dsi(AFPObj *obj)
                 dsi->datalen = DSI_DATASIZ;
                 child.flags |= CHILD_RUNNING;
 
-                afpcmpstr = AfpNum2name(function);
-                LOG(log_debug, logtype_afpd, "=> Start AFP command: %s", afpcmpstr);
+                LOG(log_debug, logtype_afpd, "=> Start AFP command: %s", AfpNum2name(function));
 
                 err = (*afp_switch[function])(obj,
-                                              dsi->commands, dsi->cmdlen,
-                                              dsi->data, &dsi->datalen);
+                                              (char *)&dsi->commands, dsi->cmdlen,
+                                              (char *)&dsi->data, &dsi->datalen);
 
-                LOG(log_debug, logtype_afpd, "=> Finished AFP command: %s", afpcmpstr);
+                LOG(log_debug, logtype_afpd, "=> Finished AFP command: %s", AfpNum2name(function));
 #ifdef FORCE_UIDGID
                /* bring everything back to old euid, egid */
                 if (obj->force_uid)
@@ -389,8 +417,9 @@ void afp_over_dsi(AFPObj *obj)
             if ( afp_switch[ function ] != NULL ) {
                 dsi->datalen = DSI_DATASIZ;
                 child.flags |= CHILD_RUNNING;
-                err = (*afp_switch[function])(obj, dsi->commands, dsi->cmdlen,
-                                              dsi->data, &dsi->datalen);
+                err = (*afp_switch[function])(obj,
+                                              (char *)&dsi->commands, dsi->cmdlen,
+                                              (char *)&dsi->data, &dsi->datalen);
                 child.flags &= ~CHILD_RUNNING;
 #ifdef FORCE_UIDGID
                /* bring everything back to old euid, egid */