]> arthur.barton.de Git - netatalk.git/commitdiff
Use function from 2-1 for local uuid generation
authorFrank Lahm <franklahm@googlemail.com>
Tue, 8 Feb 2011 19:27:33 +0000 (20:27 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 8 Feb 2011 19:27:33 +0000 (20:27 +0100)
NEWS
etc/afpd/acls.c
include/atalk/uuid.h
libatalk/acl/uuid.c

diff --git a/NEWS b/NEWS
index 93184a09c74bf0efc76a9f4905a573e74a0483e8..5c16be9f3cad23e0b2f6c5345979254bcd418193 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,8 @@ Changes in 2.1.6
 ================
 
 * FIX: afpd: Fix for LDAP user cache corruption
+* FIX: afpd: Fix for not shown ACLs for when filesyem uid or gid
+       couldn't be resolved because (eg deleted users/groups)
 * FIX: gentoo: cannot set $CNID_CONFIG
 * FIX: ubuntu: servername was empty
 * FIX: Solaris: configure script failed to enable DDP module
index a82d326fe2ff9211b58151617e037272ff45e814..206f2d9f2f774f58c46b4c90e5067ebfd3da7abb 100644 (file)
@@ -1293,11 +1293,14 @@ int afp_getacl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size
     /* Shall we return owner UUID ? */
     if (bitmap & kFileSec_UUID) {
         LOG(log_debug, logtype_afpd, "afp_getacl: client requested files owner user UUID");
-        if (NULL == (pw = getpwuid(s_path->st.st_uid)))
-            return AFPERR_MISC;
-        LOG(log_debug, logtype_afpd, "afp_getacl: got uid: %d, name: %s", s_path->st.st_uid, pw->pw_name);
-        if ((ret = getuuidfromname(pw->pw_name, UUID_USER, rbuf)) != 0)
-            return AFPERR_MISC;
+        if (NULL == (pw = getpwuid(s_path->st.st_uid))) {
+            LOG(log_debug, logtype_afpd, "afp_getacl: local uid: %u", s_path->st.st_uid);
+            localuuid_from_id(rbuf, UUID_USER, s_path->st.st_uid);
+        } else {
+            LOG(log_debug, logtype_afpd, "afp_getacl: got uid: %d, name: %s", s_path->st.st_uid, pw->pw_name);
+            if ((ret = getuuidfromname(pw->pw_name, UUID_USER, rbuf)) != 0)
+                return AFPERR_MISC;
+        }
         rbuf += UUID_BINSIZE;
         *rbuflen += UUID_BINSIZE;
     }
@@ -1305,11 +1308,14 @@ int afp_getacl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size
     /* Shall we return group UUID ? */
     if (bitmap & kFileSec_GRPUUID) {
         LOG(log_debug, logtype_afpd, "afp_getacl: client requested files owner group UUID");
-        if (NULL == (gr = getgrgid(s_path->st.st_gid)))
-            return AFPERR_MISC;
-        LOG(log_debug, logtype_afpd, "afp_getacl: got gid: %d, name: %s", s_path->st.st_gid, gr->gr_name);
-        if ((ret = getuuidfromname(gr->gr_name, UUID_GROUP, rbuf)) != 0)
-            return AFPERR_MISC;
+        if (NULL == (gr = getgrgid(s_path->st.st_gid))) {
+            LOG(log_debug, logtype_afpd, "afp_getacl: local gid: %u", s_path->st.st_gid);
+            localuuid_from_id(rbuf, UUID_GROUP, s_path->st.st_gid);
+        } else {
+            LOG(log_debug, logtype_afpd, "afp_getacl: got gid: %d, name: %s", s_path->st.st_gid, gr->gr_name);
+            if ((ret = getuuidfromname(gr->gr_name, UUID_GROUP, rbuf)) != 0)
+                return AFPERR_MISC;
+        }
         rbuf += UUID_BINSIZE;
         *rbuflen += UUID_BINSIZE;
     }
index e3b2be118b19cb317694cad350e55c158809c8a5..a9432675af5dd2dac68dd0d5352676a6a0d9213e 100644 (file)
@@ -42,6 +42,8 @@ extern char *ldap_uid_attr;
 
 extern int getuuidfromname( const char *name, uuidtype_t type, uuidp_t uuid);
 extern int getnamefromuuid( const uuidp_t uuidp, char **name, uuidtype_t *type);
+
+extern void localuuid_from_id(unsigned char *buf, uuidtype_t type, unsigned int id);
 extern const char *uuid_bin2string(unsigned char *uuid);
 extern void uuid_string2bin( const char *uuidstring, uuidp_t uuid);
 
index 8993acc21f61fa38bc0c58dda11bd720eebc0cf4..074d9deb8a76c1da0343292b6250d940ee09d5c2 100644 (file)
@@ -39,6 +39,34 @@ char *uuidtype[] = {"NULL","USER", "GROUP", "LOCAL"};
  * Public helper function
  ********************************************************/
 
+static unsigned char local_group_uuid[] = {0xab, 0xcd, 0xef,
+                                           0xab, 0xcd, 0xef,
+                                           0xab, 0xcd, 0xef, 
+                                           0xab, 0xcd, 0xef};
+
+static unsigned char local_user_uuid[] = {0xff, 0xff, 0xee, 0xee, 0xdd, 0xdd,
+                                          0xcc, 0xcc, 0xbb, 0xbb, 0xaa, 0xaa};
+
+void localuuid_from_id(unsigned char *buf, uuidtype_t type, unsigned int id)
+{
+    uint32_t tmp;
+
+    switch (type) {
+    case UUID_GROUP:
+        memcpy(buf, local_group_uuid, 12);
+        break;
+    case UUID_USER:
+    default:
+        memcpy(buf, local_user_uuid, 12);
+        break;
+    }
+
+    tmp = htonl(id);
+    memcpy(buf + 12, &tmp, 4);
+
+    return;
+}
+
 /* 
  * convert ascii string that can include dashes to binary uuid.
  * caller must provide a buffer.
@@ -99,14 +127,6 @@ const char *uuid_bin2string(unsigned char *uuid) {
  * Interface
  ********************************************************/
 
-static unsigned char local_group_uuid[] = {0xab, 0xcd, 0xef,
-                                           0xab, 0xcd, 0xef,
-                                           0xab, 0xcd, 0xef, 
-                                           0xab, 0xcd, 0xef};
-
-static unsigned char local_user_uuid[] = {0xff, 0xff, 0xee, 0xee, 0xdd, 0xdd,
-                                          0xcc, 0xcc, 0xbb, 0xbb, 0xaa, 0xaa};
-
 /*
  *   name: give me his name
  *   type: and type (UUID_USER or UUID_GROUP)
@@ -138,27 +158,21 @@ int getuuidfromname( const char *name, uuidtype_t type, uuidp_t uuid) {
         if (ret != 0) {
             /* Build a local UUID */
             if (type == UUID_USER) {
-                memcpy(uuid, local_user_uuid, 12);
                 struct passwd *pwd;
                 if ((pwd = getpwnam(name)) == NULL) {
                     LOG(log_error, logtype_afpd, "getuuidfromname(\"%s\",t:%u): unknown user",
                         name, uuidtype[type]);
                     goto cleanup;
                 }
-                uint32_t id = pwd->pw_uid;
-                id = htonl(id);
-                memcpy(uuid + 12, &id, 4);
+                localuuid_from_id(uuid, UUID_USER, pwd->pw_uid);
             } else {
-                memcpy(uuid, &local_group_uuid, 12);
                 struct group *grp;
                 if ((grp = getgrnam(name)) == NULL) {
                     LOG(log_error, logtype_afpd, "getuuidfromname(\"%s\",t:%u): unknown user",
                         name, uuidtype[type]);
                     goto cleanup;
                 }
-                uint32_t id = grp->gr_gid;
-                id = htonl(id);
-                memcpy(uuid + 12, &id, 4);
+                localuuid_from_id(uuid, UUID_GROUP, grp->gr_gid);
             }
             LOG(log_debug, logtype_afpd, "getuuidfromname{local}: name: %s, type: %s -> UUID: %s",
                 name, uuidtype[type], uuid_bin2string(uuid));