/*
- $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
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);
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);
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);
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 */
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
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
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) {