]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/server_ipc.c
afpd set the logger default to log_info and move some log msgs to log_debug
[netatalk.git] / libatalk / util / server_ipc.c
index 6881bb8f4c2885ccaae344e2ea8c5afc5d033086..289197fb7ac89a76c2da7e0cd91a3abfa2527e96 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: server_ipc.c,v 1.1 2003-05-16 15:29:28 didg Exp $
+ * $Id: server_ipc.c,v 1.4 2010-01-21 14:14:49 didg Exp $
  *
  * All rights reserved. See COPYRIGHT.
  *
@@ -26,6 +26,7 @@
 typedef struct ipc_header {
        u_int16_t command;
         pid_t    child_pid;
+        uid_t     uid;
         u_int32_t len;
        char      *msg;
 } ipc_header;
@@ -41,7 +42,7 @@ void *server_ipc_create(void)
 }
 
 /* ----------------- */
-int server_ipc_child(void *obj)
+int server_ipc_child(void *obj _U_)
 {
     /* close input */
     close(pipe_fd[0]);
@@ -49,13 +50,13 @@ int server_ipc_child(void *obj)
 }
 
 /* ----------------- */
-int server_ipc_parent(void *obj)
+int server_ipc_parent(void *obj _U_)
 {
     return pipe_fd[0];
 }
 
 /* ----------------- */
-int ipc_kill_token (struct ipc_header *ipc, server_child *children)
+static int ipc_kill_token (struct ipc_header *ipc, server_child *children)
 {
     pid_t pid;
 
@@ -65,13 +66,13 @@ int ipc_kill_token (struct ipc_header *ipc, server_child *children)
     /* assume signals SA_RESTART set */
     memcpy (&pid, ipc->msg, sizeof(pid_t));
 
-    LOG(log_info, logtype_default, "child %d disconnected", pid); 
-    server_child_kill_one(children, CHILD_DSIFORK, pid);
+    LOG(log_info, logtype_default, "child %d user %d disconnected", pid, ipc->uid);
+    server_child_kill_one(children, CHILD_DSIFORK, pid, ipc->uid);
     return 0;
 }
 
 /* ----------------- */
-int ipc_get_session (struct ipc_header *ipc, server_child *children)
+static int ipc_get_session (struct ipc_header *ipc, server_child *children)
 {
     u_int32_t boottime;
     u_int32_t idlen;
@@ -97,16 +98,22 @@ int ipc_get_session (struct ipc_header *ipc, server_child *children)
     }
     memcpy (clientid, p, idlen);
   
-    server_child_kill_one_by_id (children, CHILD_DSIFORK, ipc->child_pid, idlen, clientid, boottime);
+    server_child_kill_one_by_id (children, CHILD_DSIFORK, ipc->child_pid, ipc->uid, idlen, clientid, boottime);
     /* FIXME byte to ascii if we want to log clientid */
-    LOG (log_info, logtype_afpd, "ipc_get_session: len: %u, idlen %d, time %x", ipc->len, idlen, boottime); 
+    LOG (log_debug, logtype_afpd, "ipc_get_session: len: %u, idlen %d, time %x", ipc->len, idlen, boottime); 
     return 0;
 }
 
-#define IPC_HEADERLEN 10
+#define IPC_HEADERLEN 14
 #define IPC_MAXMSGSIZE 90
 
-/* ----------------- */
+/* ----------------- 
+ * Ipc format
+ * command
+ * pid
+ * uid
+ * 
+*/
 int server_ipc_read(server_child *children)
 {
     int       ret = 0;
@@ -119,10 +126,16 @@ int server_ipc_read(server_child *children)
     } 
 
     p = buf;
+
     memcpy(&ipc.command, p, sizeof(ipc.command));
     p += sizeof(ipc.command);
+
     memcpy(&ipc.child_pid, p, sizeof(ipc.child_pid));
     p += sizeof(ipc.child_pid);
+
+    memcpy(&ipc.uid, p, sizeof(ipc.uid));
+    p += sizeof(ipc.uid);
+
     memcpy(&ipc.len, p, sizeof(ipc.len));
 
     /* This should never happen */
@@ -134,14 +147,14 @@ int server_ipc_read(server_child *children)
 
     memset (buf, 0, IPC_MAXMSGSIZE);
     if ( ipc.len != 0) {
-           if ((ret = read(pipe_fd[0], buf, ipc.len)) != ipc.len) {
+           if ((ret = read(pipe_fd[0], buf, ipc.len)) != (int) ipc.len) {
                LOG (log_info, logtype_afpd, "Reading IPC message failed (%u of %u  bytes read)", ret, ipc.len);
                return -1;
        }        
     }
     ipc.msg = buf;
     
-    LOG (log_info, logtype_afpd, "ipc_read: command: %u, pid: %u, len: %u", ipc.command, ipc.child_pid, ipc.len); 
+    LOG (log_debug, logtype_afpd, "ipc_read: command: %u, pid: %u, len: %u", ipc.command, ipc.child_pid, ipc.len); 
 
     switch (ipc.command)
     {
@@ -163,6 +176,7 @@ int server_ipc_write( u_int16_t command, int len, void *msg)
 {
    char block[IPC_MAXMSGSIZE], *p;
    pid_t pid;
+   uid_t uid;
    p = block;
 
    memset ( p, 0 , IPC_MAXMSGSIZE);
@@ -175,13 +189,22 @@ int server_ipc_write( u_int16_t command, int len, void *msg)
    pid = getpid();
    memcpy(p, &pid, sizeof(pid_t));
    p += sizeof(pid_t);
+   
+   /* FIXME 
+    * using uid is wrong. It will not disconnect if the new connection
+    * is with a different user. 
+    * But we really don't want a remote kill command.
+   */
+   uid = geteuid();
+   memcpy(p, &uid, sizeof(uid_t));
+   p += sizeof(uid_t);
 
    memcpy(p, &len, 4);
    p += 4;
 
    memcpy(p, msg, len);
 
-   LOG (log_info, logtype_afpd, "ipc_write: command: %u, pid: %u, msglen: %u", command, pid, len); 
+   LOG (log_debug, logtype_afpd, "ipc_write: command: %u, pid: %u, msglen: %u", command, pid, len); 
    return write(pipe_fd[1], block, len+IPC_HEADERLEN );
 }