]> arthur.barton.de Git - netatalk.git/commitdiff
MachineType string is up to 16 characters
authorHAT <hat@fa2.so-net.ne.jp>
Thu, 14 Jul 2011 15:01:13 +0000 (00:01 +0900)
committerHAT <hat@fa2.so-net.ne.jp>
Thu, 14 Jul 2011 15:01:13 +0000 (00:01 +0900)
Merge remote-tracking branch 'remotes/origin/branch-netatalk-2-1'

etc/afpd/auth.c
etc/afpd/status.c
etc/afpd/status.h

index 566a8d0e05b1b838ddc5e2dceef29463e9c33d03..eb9b58dde5f0f25604bd33c7930ad057b134906e 100644 (file)
@@ -250,6 +250,23 @@ static int set_auth_switch(int expired)
     return AFP_OK;
 }
 
+#define GROUPSTR_BUFSIZE 1024
+static const char *print_groups(int ngroups, gid_t *groups)
+{
+    static char groupsstr[GROUPSTR_BUFSIZE];
+    int i;
+    char *s = groupsstr;
+
+    if (ngroups == 0)
+        return "-";
+
+    for (i = 0; (i < ngroups) && (s < &groupsstr[GROUPSTR_BUFSIZE]); i++) {
+        s += snprintf(s, &groupsstr[GROUPSTR_BUFSIZE] - s, " %u", groups[i]);
+    }
+
+    return groupsstr;
+}
+
 static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expired)
 {
 #ifdef ADMIN_GRP
@@ -391,28 +408,7 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi
     }
 #endif /* TRU64 */
 
-    if (ngroups > 0) {
-        #define GROUPSTR_BUFSIZE 1024
-        char groupsstr[GROUPSTR_BUFSIZE];
-        char *s = groupsstr;
-        int j = GROUPSTR_BUFSIZE;
-
-        int n = snprintf(groupsstr, GROUPSTR_BUFSIZE, "%u", groups[0]);
-        j -= n;
-        s += n;
-
-        for (int i = 1; i < ngroups; i++) {
-            n = snprintf(s, j, ", %u", groups[i]);
-            if (n == j) {
-                /* Buffer full */
-                LOG(log_debug, logtype_afpd, "login: group string buffer overflow");
-                break;
-            }
-            j -= n;
-            s += n;
-        }
-        LOG(log_debug, logtype_afpd, "login: %u supplementary groups: %s", ngroups, groupsstr);
-    }
+    LOG(log_debug, logtype_afpd, "login: supplementary groups: %s", print_groups(ngroups, groups));
 
     /* There's probably a better way to do this, but for now, we just play root */
 #ifdef ADMIN_GRP
index cbf59892c157143fb74d9fef60b0de4f12a04bb1..ae51d26e28cc7fa973d133858f208fb761866d35 100644 (file)
@@ -130,13 +130,13 @@ static void status_machine(char *data)
 #else /* !AFS */
     const char         *machine = "Netatalk %s";
 #endif /* AFS */
-    char buf[64];
+    char buf[AFPSTATUS_MACHLEN+1];
 
     memcpy(&status, start + AFPSTATUS_MACHOFF, sizeof(status));
     data += ntohs( status );
 
     //    len = strlen( machine );
-    len = snprintf(buf, 64, machine, VERSION);
+    len = snprintf(buf, AFPSTATUS_MACHLEN+1, machine, VERSION);
     *data++ = len;
     memcpy( data, buf, len );
     data += len;
index 3a29a17418f092681bbf986e7de0a6b365158f91..d97fa1773df2b220bb2451b6a9f17fc9fc768405 100644 (file)
@@ -13,6 +13,7 @@
 #define AFPSTATUS_UAMSOFF     4
 #define AFPSTATUS_ICONOFF     6
 #define AFPSTATUS_FLAGOFF     8
+
 /* AFPSTATUS_PRELEN is the number of bytes for status data prior to 
  * the ServerName field.
  *
@@ -20,6 +21,7 @@
  * UAMCount, VolumeIconAndMask, and the 16-bit "Fixed" status flags.
  */
 #define AFPSTATUS_PRELEN     10
+
 /* AFPSTATUS_POSTLEN is the number of bytes for offset records
  * after the ServerName field.
  *
@@ -29,6 +31,9 @@
 #define AFPSTATUS_POSTLEN     8
 #define AFPSTATUS_LEN        (AFPSTATUS_PRELEN + AFPSTATUS_POSTLEN)
 
+/* AFPSTATUS_MACHLEN is the number of characters for the MachineType. */
+#define AFPSTATUS_MACHLEN     16
+
 
 #define PASSWD_NONE     0
 #define PASSWD_SET     (1 << 0)