winbindd_util: add fill_domain_username_talloc().
authorMichael Adam <obnox@samba.org>
Mon, 22 Sep 2008 08:37:11 +0000 (10:37 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 21 Nov 2008 23:30:56 +0000 (00:30 +0100)
A talloc version of fill_domain_username().

Michael

source/winbindd/winbindd_util.c

index cd79c777eaa8cb37ad01700d8f4f5dd12274ac75..a2a248b682137cff9ccbc1c651054278efadb872 100644 (file)
@@ -1195,6 +1195,33 @@ void fill_domain_username(fstring name, const char *domain, const char *user, bo
        }
 }
 
+/**
+ * talloc version of fill_domain_username()
+ * return NULL on talloc failure.
+ */
+char *fill_domain_username_talloc(TALLOC_CTX *mem_ctx,
+                                 const char *domain,
+                                 const char *user,
+                                 bool can_assume)
+{
+       char *tmp_user, *name;
+
+       tmp_user = talloc_strdup(mem_ctx, user);
+       strlower_m(tmp_user);
+
+       if (can_assume && assume_domain(domain)) {
+               name = tmp_user;
+       } else {
+               name = talloc_asprintf(mem_ctx, "%s%c%s",
+                                      domain,
+                                      *lp_winbind_separator(),
+                                      tmp_user);
+               TALLOC_FREE(tmp_user);
+       }
+
+       return name;
+}
+
 /*
  * Winbindd socket accessor functions
  */