]> arthur.barton.de Git - netatalk.git/commitdiff
Check for local user UUIDs too
authorFrank Lahm <franklahm@googlemail.com>
Thu, 21 Oct 2010 16:18:35 +0000 (18:18 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 21 Oct 2010 16:18:35 +0000 (18:18 +0200)
bin/misc/uuidtest.c
etc/afpd/directory.c
libatalk/acl/uuid.c

index cb9177edd7e26e8c758076447307ba2987c050e9..a52670a4eaa1923ead10bac1d493915891a522d5 100644 (file)
@@ -1,5 +1,4 @@
 /*
-  $Id: uuidtest.c,v 1.3 2009-11-28 12:27:24 franklahm Exp $
   Copyright (c) 2008,2009 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
@@ -123,10 +122,17 @@ int main( int argc, char **argv)
             uuid_string2bin(optarg, uuid);
             ret = getnamefromuuid( uuid, &name, &type);
             if (ret == 0) {
-                if (type == UUID_USER)
+                switch (type) {
+                case UUID_LOCAL:
+                    printf("local UUID: %s\n", optarg);
+                    break;
+                case UUID_USER:
                     printf("UUID: %s ==> User: %s\n", optarg, name);
-                else
+                    break;
+                case UUID_GROUP:
                     printf("UUID: %s ==> Group: %s\n", optarg, name);
+                    break;
+                }
                 free(name);
             } else {
                 printf("UUID: %s not found.\n", optarg);
index 813fb05475ccec50cc9e40dda06ebac3a5bf2b06..ee4553df7e7257f2658486bdcb7d997081bbeddb 100644 (file)
@@ -2344,7 +2344,8 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r
         len = getnamefromuuid( ibuf, &name, &type);
         if (len != 0)       /* its a error code, not len */
             return AFPERR_NOITEM;
-        if (type == UUID_USER) {
+        switch (type) {
+        case UUID_USER:
             if (( pw = getpwnam( name )) == NULL )
                 return( AFPERR_NOITEM );
             LOG(log_debug, logtype_afpd, "afp_mapid: name:%s -> uid:%d", name, pw->pw_uid);
@@ -2355,7 +2356,8 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r
             memcpy( rbuf, &id, sizeof( id ));
             rbuf += sizeof( id );
             *rbuflen = 2 * sizeof( id );
-        } else {        /* type == UUID_GROUP */
+            break;
+        case UUID_GROUP:
             if (( gr = getgrnam( name )) == NULL )
                 return( AFPERR_NOITEM );
             LOG(log_debug, logtype_afpd, "afp_mapid: group:%s -> gid:%d", name, gr->gr_gid);
@@ -2366,6 +2368,12 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r
             memcpy( rbuf, &id, sizeof( id ));
             rbuf += sizeof( id );
             *rbuflen = 2 * sizeof( id );
+            break;
+        case UUID_LOCAL:
+            free(name);
+            return (AFPERR_NOITEM);
+        default:
+            return AFPERR_MISC;
         }
         break;
 #endif /* HAVE_ACLS */
index 7891031875bd7feec0ede15b7141c500c4302f0a..29d9c2adfabd83f2ae853301ee41eaf84a4c301f 100644 (file)
@@ -145,11 +145,15 @@ cleanup:
     return ret;
 }
 
-static char local_uuid[] = {0xab, 0xcd, 0xef,
-                            0xab, 0xcd, 0xef,
-                            0xab, 0xcd, 0xef, 
-                            0xab, 0xcd, 0xef};
-/* 
+static char local_group_uuid[] = {0xab, 0xcd, 0xef,
+                                  0xab, 0xcd, 0xef,
+                                  0xab, 0xcd, 0xef, 
+                                  0xab, 0xcd, 0xef};
+
+static char local_user_uuid[] = {0xff, 0xff, 0xee, 0xee, 0xdd, 0xdd,
+                                 0xcc, 0xcc, 0xbb, 0xbb, 0xaa, 0xaa};
+
+/*
  * uuidp: pointer to a uuid
  * name: returns allocated buffer from ldap_getnamefromuuid
  * type: returns USER, GROUP or LOCAL
@@ -161,15 +165,6 @@ int getnamefromuuid(const uuidp_t uuidp, char **name, uuidtype_t *type) {
     int ret;
     char *uuid_string = NULL;
 
-    /* Check if UUID is ABCDEFAB-CDEF-ABCD-EFAB-CDEFXXXXXXXX, where X is a client local uid */
-    if (memcmp(uuidp, local_uuid, 12) == 0) {
-        LOG(log_debug, logtype_afpd, "getnamefromuuid: local UUID: %" PRIu32 "",
-            ntohl(*(uint32_t *)(uuid_string+12)));
-        *type = UUID_LOCAL;
-        *name = strdup("UUID_LOCAL");
-        return 0;
-    }
-
     ret = search_cachebyuuid( uuidp, name, type);
     if (ret == 0) {     /* found in cache */
 #ifdef DEBUG
@@ -180,6 +175,17 @@ int getnamefromuuid(const uuidp_t uuidp, char **name, uuidtype_t *type) {
         uuid_string = NULL;
 #endif
     } else  {                   /* if not found in cache */
+
+        /* Check if UUID is a client local one */
+        if (memcmp(uuidp, local_user_uuid, 12) == 0
+            || memcmp(uuidp, local_group_uuid, 12) == 0) {
+            LOG(log_debug, logtype_afpd, "getnamefromuuid: local UUID: %" PRIu32 "",
+                ntohl(*(uint32_t *)(uuid_string+12)));
+            *type = UUID_LOCAL;
+            *name = strdup("UUID_LOCAL");
+            return 0;
+        }
+
         uuid_bin2string( uuidp, &uuid_string);
         ret = ldap_getnamefromuuid( uuid_string, name, type);
         if (ret != 0) {