/* * Calculate the set of rights the user in 'auth_state' has in the ACL 'acl'. * 'acl' must be writable, but is restored to its original condition. */ EXPORTED int cyrus_acl_myrights(struct auth_state *auth_state, const char *origacl) { char *acl = xstrdupsafe(origacl); char *thisid, *rights, *nextid; long acl_positive = 0, acl_negative = 0; long *acl_ptr; for (thisid = acl; *thisid; thisid = nextid) { acl_ptr = &acl_positive; rights = strchr(thisid, '\t'); if (!rights) { break; } *rights++ = '\0'; nextid = strchr(rights, '\t'); if (!nextid) { rights[-1] = '\t'; break; } *nextid++ = '\0'; if (*thisid == '-') { acl_ptr = &acl_negative; thisid++; } if (auth_memberof(auth_state, thisid)) { *acl_ptr |= cyrus_acl_strtomask(rights); } } free(acl); return acl_positive & ~acl_negative; }
int main(void) { char cacheid[16]="4224423"; openlog("testr", LOG_PID, SYSLOG_FACILITY); if (!auth_setid("*****@*****.**",cacheid)) printf ("Auth_memberof(cg2v,cg2v:me) is %d\n", auth_memberof("cg2v:me")); else printf ("Auth_setid([email protected]) failed\n"); }
int main(int argc, char **argv) { char *cacheid; char cache[16]; if (argc < 3 || argc > 4) { printf("Usage: pttset user group [cachearg]\n"); exit(1); } if (argc == 4) { memset(cache,0,16); strncpy(cache,argv[3],16); cacheid=cache; } else cacheid=NULL; openlog("pttest", LOG_PID, SYSLOG_FACILITY); if (!auth_setid(argv[1],cacheid)) printf ("Auth_memberof(%s,%s) is %d\n", argv[1], argv[2], auth_memberof(argv[2])); else printf ("Auth_setid(%s) failed\n", argv[1]); }