/* * smb_sid_split * * Take a full sid and split it into a domain sid and a relative id (rid). * The domain SID is allocated and a pointer to it will be returned. The * RID value is passed back in 'rid' arg if it's not NULL. The allocated * memory for the domain SID must be freed by caller. */ smb_sid_t * smb_sid_split(smb_sid_t *sid, uint32_t *rid) { smb_sid_t *domsid; int size; if (!smb_sid_isvalid(sid) || (sid->sid_subauthcnt == 0)) return (NULL); /* * We will reduce sid_subauthcnt by one, because * the domain SID does not include the RID. */ size = smb_sid_len(sid) - sizeof (uint32_t); if ((domsid = smb_sid_alloc(size)) == NULL) return (NULL); bcopy(sid, domsid, size); domsid->sid_subauthcnt = sid->sid_subauthcnt - 1; if (rid) *rid = sid->sid_subauth[sid->sid_subauthcnt - 1]; return (domsid); }
/* * smb_sid_dup * * Make a duplicate of the specified sid. The memory for the new sid * should be freed by calling smb_sid_free(). * A pointer to the new sid is returned. */ smb_sid_t * smb_sid_dup(smb_sid_t *sid) { smb_sid_t *new_sid; int size; if (sid == NULL) return (NULL); size = smb_sid_len(sid); if ((new_sid = smb_sid_alloc(size)) == NULL) return (NULL); bcopy(sid, new_sid, size); return (new_sid); }
/* * smb_sid_splice * * Make a full sid from a domain sid and a relative id (rid). * The memory for the result sid should be freed by calling * smb_sid_free(). A pointer to the new sid is returned. */ smb_sid_t * smb_sid_splice(smb_sid_t *domain_sid, uint32_t rid) { smb_sid_t *sid; int size; if (domain_sid == NULL) return (NULL); size = smb_sid_len(domain_sid); if ((sid = smb_sid_alloc(size + sizeof (rid))) == NULL) return (NULL); bcopy(domain_sid, sid, size); sid->sid_subauth[domain_sid->sid_subauthcnt] = rid; ++sid->sid_subauthcnt; return (sid); }