]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/acl/uuid.c
Merge master
[netatalk.git] / libatalk / acl / uuid.c
index 8993acc21f61fa38bc0c58dda11bd720eebc0cf4..4b9703617b18d7f2cbc122b2be2685c4e29d3230 100644 (file)
@@ -39,11 +39,39 @@ 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.
  */
-void uuid_string2bin( const char *uuidstring, uuidp_t uuid) {
+void uuid_string2bin( const char *uuidstring, unsigned char *uuid) {
     int nibble = 1;
     int i = 0;
     unsigned char c, val = 0;
@@ -77,7 +105,7 @@ void uuid_string2bin( const char *uuidstring, uuidp_t uuid) {
  * 
  * Returns pointer to static buffer.
  */
-const char *uuid_bin2string(unsigned char *uuid) {
+const char *uuid_bin2string(const unsigned char *uuid) {
     static char uuidstring[UUID_STRINGSIZE + 1];
 
     int i = 0;
@@ -99,21 +127,13 @@ 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)
  *   uuid: pointer to uuid_t storage that the caller must provide
  * returns 0 on success !=0 on errror
  */  
-int getuuidfromname( const char *name, uuidtype_t type, uuidp_t uuid) {
+int getuuidfromname( const char *name, uuidtype_t type, unsigned char *uuid) {
     int ret = 0;
 #ifdef HAVE_LDAP
     char *uuid_string = NULL;
@@ -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));
@@ -183,7 +197,7 @@ cleanup:
  *
  * Caller must free name appropiately.
  */
-int getnamefromuuid(const uuidp_t uuidp, char **name, uuidtype_t *type) {
+int getnamefromuuid(uuidp_t uuidp, char **name, uuidtype_t *type) {
     int ret;
 
     ret = search_cachebyuuid( uuidp, name, type);