summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/security/dom_sid.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/source4/libcli/security/dom_sid.c b/source4/libcli/security/dom_sid.c
index 36e3967910..a83ebb0aa1 100644
--- a/source4/libcli/security/dom_sid.c
+++ b/source4/libcli/security/dom_sid.c
@@ -84,31 +84,26 @@ bool dom_sid_equal(const struct dom_sid *sid1, const struct dom_sid *sid2)
return dom_sid_compare(sid1, sid2) == 0;
}
-
-/*
- convert a string to a dom_sid, returning a talloc'd dom_sid
-*/
-struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr)
+bool dom_sid_parse(const char *sidstr, struct dom_sid *ret)
{
- struct dom_sid *ret;
uint_t rev, ia, num_sub_auths, i;
char *p;
if (strncasecmp(sidstr, "S-", 2)) {
- return NULL;
+ return false;
}
sidstr += 2;
rev = strtol(sidstr, &p, 10);
if (*p != '-') {
- return NULL;
+ return false;
}
sidstr = p+1;
ia = strtol(sidstr, &p, 10);
if (p == sidstr) {
- return NULL;
+ return false;
}
sidstr = p;
@@ -117,11 +112,6 @@ struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr)
if (sidstr[i] == '-') num_sub_auths++;
}
- ret = talloc(mem_ctx, struct dom_sid);
- if (!ret) {
- return NULL;
- }
-
ret->sid_rev_num = rev;
ret->id_auth[0] = 0;
ret->id_auth[1] = 0;
@@ -133,16 +123,34 @@ struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr)
for (i=0;i<num_sub_auths;i++) {
if (sidstr[0] != '-') {
- return NULL;
+ return false;
}
sidstr++;
ret->sub_auths[i] = strtoul(sidstr, &p, 10);
if (p == sidstr) {
- return NULL;
+ return false;
}
sidstr = p;
}
+ return true;
+}
+
+/*
+ convert a string to a dom_sid, returning a talloc'd dom_sid
+*/
+struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr)
+{
+ struct dom_sid *ret;
+ ret = talloc(mem_ctx, struct dom_sid);
+ if (!ret) {
+ return NULL;
+ }
+ if (!dom_sid_parse(sidstr, ret)) {
+ talloc_free(ret);
+ return NULL;
+ }
+
return ret;
}