]> arthur.barton.de Git - netatalk.git/commitdiff
FPDisconnect only if it's the same user. It's against the spec but we don't
authordidg <didg>
Thu, 1 Jul 2004 01:27:34 +0000 (01:27 +0000)
committerdidg <didg>
Thu, 1 Jul 2004 01:27:34 +0000 (01:27 +0000)
want a remote kill command.

etc/afpd/auth.c
include/atalk/server_child.h
libatalk/util/server_child.c
libatalk/util/server_ipc.c

index 150977351dd95c0631562c1553674f4e803078df..ef92c64d3c7a89cc88077846f1e8a3c742e8aed8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: auth.c,v 1.44.2.3.2.14 2004-06-18 07:58:20 bfernhomberg Exp $
+ * $Id: auth.c,v 1.44.2.3.2.15 2004-07-01 01:27:34 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -457,6 +457,8 @@ unsigned int ibuflen, *rbuflen;
     */
     switch (type) {
     case 0: /* old version ?*/
+            tklen = obj->sinfo.sessiontoken_len;
+            token = obj->sinfo.sessiontoken;
         break;
     case 1: /* disconnect */
     case 2: /* reconnect update id */
@@ -531,10 +533,12 @@ int               ibuflen, *rbuflen;
     *rbuflen = 0;
     ibuf += 2;
 
+#if 0
     /* check for guest user */
     if ( 0 == (strcasecmp(obj->username, obj->options.guest)) ) {
         return AFPERR_MISC;
     }
+#endif
 
     memcpy(&type, ibuf, sizeof(type));
     type = ntohs(type);
index d371ef27615eb6f05ebde930d730aac4a78c4421..aeee9439bc33469ad77f140f759b5910e8dc38b3 100644 (file)
@@ -30,8 +30,8 @@ extern int server_child_remove __P((server_child *, const int, const pid_t));
 extern void server_child_free __P((server_child *));
 
 extern void server_child_kill __P((server_child *, const int, const int));
-extern void server_child_kill_one __P((server_child *children, const int forkid, const pid_t pid));
-extern void server_child_kill_one_by_id __P((server_child *children, const int forkid, const pid_t pid, 
+extern void server_child_kill_one __P((server_child *children, const int forkid, const pid_t, const uid_t));
+extern void server_child_kill_one_by_id __P((server_child *children, const int forkid, const pid_t pid, const uid_t,
                                                const u_int32_t len, char *id, u_int32_t boottime));
 
 extern void server_child_setup __P((server_child *, const int, void (*)()));
index 2e1f3e1618cd973eb7fbaeee538e6f5dd04f36ec..548388e7718b8cd60afac753e00991047589a989 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: server_child.c,v 1.7.4.1.2.3 2004-02-16 08:59:52 didg Exp $
+ * $Id: server_child.c,v 1.7.4.1.2.4 2004-07-01 01:27:34 didg Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * All rights reserved. See COPYRIGHT.
 #define HASH(i) ((((i) >> 8) ^ (i)) & (CHILD_HASHSIZE - 1))
 
 struct server_child_data {
-  pid_t pid; 
-  u_int32_t  time;
+  pid_t     pid; 
+  uid_t     uid;
+  int       valid;
+  u_int32_t time;
   u_int32_t idlen;
   
   char *clientid;
@@ -166,6 +168,7 @@ int server_child_add(server_child *children, const int forkid,
   }
 
   child->pid = pid;
+  child->valid = 0;
   hash_child(fork->table, child);
   children->count++;
   sigprocmask(SIG_SETMASK, &oldsig, NULL);
@@ -243,7 +246,7 @@ void server_child_kill(server_child *children, const int forkid,
  * a plain-old linked list 
  * FIXME use resolve_child ?
  */
-void server_child_kill_one(server_child *children, const int forkid, const pid_t pid)
+void server_child_kill_one(server_child *children, const int forkid, const pid_t pid, const uid_t uid)
 {
   server_child_fork *fork;
   struct server_child_data *child, *tmp;
@@ -255,7 +258,16 @@ void server_child_kill_one(server_child *children, const int forkid, const pid_t
     while (child) {
       tmp = child->next;
       if (child->pid == pid) {
-          kill(child->pid, SIGTERM);
+          if (!child->valid) {
+             /* hmm, client 'guess' the pid, rogue? */
+             LOG(log_info, logtype_default, "Disconnecting old session (%d) no token, bailout!",  child->pid);
+          }
+          else if (child->uid != uid) {
+             LOG(log_info, logtype_default, "Disconnecting old session (%d) not the same user, bailout!",  child->pid);
+          }
+          else {
+              kill(child->pid, SIGTERM);
+          }
       }
       child = tmp;
     }
@@ -265,7 +277,8 @@ void server_child_kill_one(server_child *children, const int forkid, const pid_t
 
 /* see if there is a process for the same mac     */
 /* if the times don't match mac has been rebooted */
-void server_child_kill_one_by_id(server_child *children, const int forkid, const pid_t pid, 
+void server_child_kill_one_by_id(server_child *children, const int forkid, const pid_t pid,
+          const uid_t uid, 
           const u_int32_t idlen, char *id, u_int32_t boottime)
 {
   server_child_fork *fork;
@@ -280,8 +293,13 @@ void server_child_kill_one_by_id(server_child *children, const int forkid, const
       if ( child->pid != pid) {
           if ( child->idlen == idlen && !memcmp(child->clientid, id, idlen)) {
             if ( child->time != boottime ) {
-                 kill(child->pid, SIGTERM);
-                 LOG(log_info, logtype_default, "Disconnecting old session %d, client rebooted.",  child->pid);
+                 if (uid == child->uid) {
+                     kill(child->pid, SIGTERM);
+                     LOG(log_info, logtype_default, "Disconnecting old session %d, client rebooted.",  child->pid);
+                 }
+                 else {
+                     LOG(log_info, logtype_default, "Disconnecting old session not the same uid, bailout!");
+                 }
             }
             else {
                  LOG(log_info, logtype_default, 
@@ -298,6 +316,8 @@ void server_child_kill_one_by_id(server_child *children, const int forkid, const
          if (child->clientid) {
              free(child->clientid);
          }
+          child->uid = uid; 
+          child->valid = 1;
          child->idlen = idlen;
           child->clientid = id;
          LOG(log_info, logtype_default, "Setting clientid (len %d) for %d, boottime %X", idlen, child->pid, boottime);
index 1f7fc15f9376e4a5fc5fb9f293547dbf6916e484..a630b93b365be1696947121e85a2c87ba2067e77 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: server_ipc.c,v 1.1.4.1.2.1 2004-01-10 08:29:16 bfernhomberg Exp $
+ * $Id: server_ipc.c,v 1.1.4.1.2.2 2004-07-01 01:27:34 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;
@@ -65,8 +66,8 @@ 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;
 }
 
@@ -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); 
     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 */
@@ -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,6 +189,15 @@ 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;