summaryrefslogtreecommitdiffstats
path: root/server/tools/tools_util.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2009-03-08 00:20:50 +0100
committerStephen Gallagher <sgallagh@redhat.com>2009-03-09 10:21:37 -0400
commit0e0a7393064a1826b31fc567f35617f3e7a134fc (patch)
tree1faa9671a5580cff004d72ea6699200986793dac /server/tools/tools_util.c
parent691c9b36947b64ccad9275ba2ec32bf9294851c9 (diff)
downloadsssd-0e0a7393064a1826b31fc567f35617f3e7a134fc.tar.gz
sssd-0e0a7393064a1826b31fc567f35617f3e7a134fc.tar.xz
sssd-0e0a7393064a1826b31fc567f35617f3e7a134fc.zip
sss_usermod
Move parse_groups into tools_utils
Diffstat (limited to 'server/tools/tools_util.c')
-rw-r--r--server/tools/tools_util.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c
index 241e1f9a1..daf9b41f4 100644
--- a/server/tools/tools_util.c
+++ b/server/tools/tools_util.c
@@ -194,3 +194,47 @@ void usage(poptContext pc, const char *error)
if (error) fprintf(stderr, "%s", error);
}
+/* FIXME: avoid using strtok !! */
+int parse_groups(TALLOC_CTX *mem_ctx, const char *optstr, char ***_out)
+{
+ char **out;
+ char *orig, *n, *o;
+ char delim = ',';
+ unsigned int tokens = 1;
+ int i;
+
+ orig = talloc_strdup(mem_ctx, optstr);
+ if (!orig) return ENOMEM;
+
+ n = orig;
+ tokens = 1;
+ while ((n = strchr(n, delim))) {
+ n++;
+ tokens++;
+ }
+
+ out = talloc_array(mem_ctx, char *, tokens+1);
+ if (!out) {
+ talloc_free(orig);
+ return ENOMEM;
+ }
+
+ n = orig;
+ for (i = 0; i < tokens; i++) {
+ o = n;
+ n = strchr(n, delim);
+ if (!n) {
+ break;
+ }
+ *n = '\0';
+ n++;
+ out[i] = talloc_strdup(out, o);
+ }
+ out[tokens-1] = talloc_strdup(out, o);
+ out[tokens] = NULL;
+
+ talloc_free(orig);
+ *_out = out;
+ return EOK;
+}
+