summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2015-08-14 17:14:53 +0200
committerRalph Boehme <slow@samba.org>2016-02-22 20:29:15 +0100
commite50c1a66486a6885fe644bce351e83d7d716f57d (patch)
treed0213cce11c6c3f7fbbec0d7298dedd625caeb83
parent5bb6600110b3eae997a1d5be2fa0089d52c829ab (diff)
downloadsamba-e50c1a66486a6885fe644bce351e83d7d716f57d.tar.gz
winbind: Add parse_xidlist()
This will be part of parsing the socket protocols xids2sids request Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
-rw-r--r--source3/winbindd/winbindd_proto.h2
-rw-r--r--source3/winbindd/winbindd_util.c64
2 files changed, 66 insertions, 0 deletions
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index bc3ac6535fd..f3c5c994957 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -468,6 +468,8 @@ bool is_domain_offline(const struct winbindd_domain *domain);
bool is_domain_online(const struct winbindd_domain *domain);
bool parse_sidlist(TALLOC_CTX *mem_ctx, const char *sidstr,
struct dom_sid **sids, uint32_t *num_sids);
+bool parse_xidlist(TALLOC_CTX *mem_ctx, const char *xidstr,
+ struct unixid **pxids, uint32_t *pnum_xids);
/* The following definitions come from winbindd/winbindd_wins.c */
diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c
index 8139daadfd7..0cd77f73263 100644
--- a/source3/winbindd/winbindd_util.c
+++ b/source3/winbindd/winbindd_util.c
@@ -1610,3 +1610,67 @@ bool parse_sidlist(TALLOC_CTX *mem_ctx, const char *sidstr,
}
return True;
}
+
+bool parse_xidlist(TALLOC_CTX *mem_ctx, const char *xidstr,
+ struct unixid **pxids, uint32_t *pnum_xids)
+{
+ const char *p;
+ struct unixid *xids = NULL;
+ uint32_t num_xids = 0;
+
+ p = xidstr;
+ if (p == NULL) {
+ return false;
+ }
+
+ while (p[0] != '\0') {
+ struct unixid *tmp;
+ struct unixid xid;
+ unsigned long long id;
+ char *endp;
+
+ switch (p[0]) {
+ case 'U':
+ xid = (struct unixid) { .type = ID_TYPE_UID };
+ break;
+ case 'G':
+ xid = (struct unixid) { .type = ID_TYPE_GID };
+ break;
+ default:
+ return false;
+ }
+
+ p += 1;
+
+ id = strtoull(p, &endp, 10);
+ if ((id == ULLONG_MAX) && (errno == ERANGE)) {
+ goto fail;
+ }
+ if (*endp != '\n') {
+ goto fail;
+ }
+ p = endp+1;
+
+ xid.id = id;
+ if ((unsigned long long)xid.id != id) {
+ goto fail;
+ }
+
+ tmp = talloc_realloc(mem_ctx, xids, struct unixid, num_xids+1);
+ if (tmp == NULL) {
+ return 0;
+ }
+ xids = tmp;
+
+ xids[num_xids] = xid;
+ num_xids += 1;
+ }
+
+ *pxids = xids;
+ *pnum_xids = num_xids;
+ return true;
+
+fail:
+ TALLOC_FREE(xids);
+ return false;
+}