s3-lib: Add grpname to talloc_sub_specified().
authorAndreas Schneider <asn@samba.org>
Mon, 18 Nov 2013 13:58:04 +0000 (14:58 +0100)
committerKarolin Seeger <kseeger@samba.org>
Tue, 26 Nov 2013 19:34:46 +0000 (20:34 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=2191

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 6366ebb79bb72d9dcb12f8fe8d6e35611fcff150)

source3/include/proto.h
source3/lib/substitute.c
source3/passdb/passdb.c
source3/passdb/pdb_ldap.c
source3/torture/torture.c
source3/utils/net_sam.c
source3/winbindd/wb_fill_pwent.c

index 0defbc96128691d1e6cc676cd5aa4f6ae7ee6e54..0276244a42516d9f20914365358f762f8b5a2b33 100644 (file)
@@ -222,6 +222,7 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name,
 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
                        const char *input_string,
                        const char *username,
+                       const char *grpname,
                        const char *domain,
                        uid_t uid,
                        gid_t gid);
index a254bcaa7d54e481d26a08c7cc866767adb85201..ca2ac7981fad5fc9b7583a5ac48ae30d62517cc1 100644 (file)
@@ -613,6 +613,7 @@ done:
 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
                        const char *input_string,
                        const char *username,
+                       const char *grpname,
                        const char *domain,
                        uid_t uid,
                        gid_t gid)
@@ -648,9 +649,18 @@ char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
                        break;
                case 'G' :
                        if (gid != -1) {
-                               a_string = talloc_string_sub(
-                                       tmp_ctx, a_string, "%G",
-                                       gidtoname(gid));
+                               const char *name;
+
+                               if (grpname != NULL) {
+                                       name = grpname;
+                               } else {
+                                       name = gidtoname(gid);
+                               }
+
+                               a_string = talloc_string_sub(tmp_ctx,
+                                                            a_string,
+                                                            "%G",
+                                                            name);
                        } else {
                                a_string = talloc_string_sub(
                                        tmp_ctx, a_string,
@@ -659,9 +669,18 @@ char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
                        break;
                case 'g' :
                        if (gid != -1) {
-                               a_string = talloc_string_sub(
-                                       tmp_ctx, a_string, "%g",
-                                       gidtoname(gid));
+                               const char *name;
+
+                               if (grpname != NULL) {
+                                       name = grpname;
+                               } else {
+                                       name = gidtoname(gid);
+                               }
+
+                               a_string = talloc_string_sub(tmp_ctx,
+                                                            a_string,
+                                                            "%g",
+                                                            name);
                        } else {
                                a_string = talloc_string_sub(
                                        tmp_ctx, a_string, "%g", "NO_GROUP");
index 379d85803f1b544dd68d49896a9f9f827253cab5..5a4620f6cb3292055672b9e38edbb294aa40d9a4 100644 (file)
@@ -228,16 +228,16 @@ static NTSTATUS samu_set_unix_internal(struct pdb_methods *methods,
                /* set some basic attributes */
 
                pdb_set_profile_path(user, talloc_sub_specified(user, 
-                       lp_logon_path(), pwd->pw_name, domain, pwd->pw_uid, pwd->pw_gid), 
+                       lp_logon_path(), pwd->pw_name, NULL, domain, pwd->pw_uid, pwd->pw_gid),
                        PDB_DEFAULT);           
                pdb_set_homedir(user, talloc_sub_specified(user, 
-                       lp_logon_home(), pwd->pw_name, domain, pwd->pw_uid, pwd->pw_gid),
+                       lp_logon_home(), pwd->pw_name, NULL, domain, pwd->pw_uid, pwd->pw_gid),
                        PDB_DEFAULT);
                pdb_set_dir_drive(user, talloc_sub_specified(user, 
-                       lp_logon_drive(), pwd->pw_name, domain, pwd->pw_uid, pwd->pw_gid),
+                       lp_logon_drive(), pwd->pw_name, NULL, domain, pwd->pw_uid, pwd->pw_gid),
                        PDB_DEFAULT);
                pdb_set_logon_script(user, talloc_sub_specified(user, 
-                       lp_logon_script(), pwd->pw_name, domain, pwd->pw_uid, pwd->pw_gid), 
+                       lp_logon_script(), pwd->pw_name, NULL, domain, pwd->pw_uid, pwd->pw_gid),
                        PDB_DEFAULT);
        }
 
index 7ae9056d181752dfeca1ab9a75b8f2a5042a9329..a9db3fad01a27368a7fb9e49d7a049e947e95eea 100644 (file)
@@ -5343,11 +5343,29 @@ static NTSTATUS ldapsam_create_user(struct pdb_methods *my_methods,
 
                if (is_machine) {
                        /* TODO: choose a more appropriate default for machines */
-                       homedir = talloc_sub_specified(tmp_ctx, lp_template_homedir(), "SMB_workstations_home", ldap_state->domain_name, uid, gid);
+                       homedir = talloc_sub_specified(tmp_ctx,
+                                                      lp_template_homedir(),
+                                                      "SMB_workstations_home",
+                                                      NULL,
+                                                      ldap_state->domain_name,
+                                                      uid,
+                                                      gid);
                        shell = talloc_strdup(tmp_ctx, "/bin/false");
                } else {
-                       homedir = talloc_sub_specified(tmp_ctx, lp_template_homedir(), name, ldap_state->domain_name, uid, gid);
-                       shell = talloc_sub_specified(tmp_ctx, lp_template_shell(), name, ldap_state->domain_name, uid, gid);
+                       homedir = talloc_sub_specified(tmp_ctx,
+                                                      lp_template_homedir(),
+                                                      name,
+                                                      NULL,
+                                                      ldap_state->domain_name,
+                                                      uid,
+                                                      gid);
+                       shell = talloc_sub_specified(tmp_ctx,
+                                                    lp_template_shell(),
+                                                    name,
+                                                    NULL,
+                                                    ldap_state->domain_name,
+                                                    uid,
+                                                    gid);
                }
                uidstr = talloc_asprintf(tmp_ctx, "%u", (unsigned int)uid);
                gidstr = talloc_asprintf(tmp_ctx, "%u", (unsigned int)gid);
index 107106cd9e17d454eff28a301b07ff207461d540..a33deb92e0450176f6a4e623014be73061c39de1 100644 (file)
@@ -6552,7 +6552,7 @@ static bool subst_test(const char *str, const char *user, const char *domain,
        char *subst;
        bool result = true;
 
-       subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
+       subst = talloc_sub_specified(talloc_tos(), str, user, NULL, domain, uid, gid);
 
        if (strcmp(subst, expected) != 0) {
                printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
index d33c354032a37c4481bb641090430dbe674d6f4d..b1c4e9b8c486c5e794e345e72d43f57d7a8dbf51 100644 (file)
@@ -1873,10 +1873,12 @@ doma_done:
                gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
                dir = talloc_sub_specified(tc, lp_template_homedir(),
                                                "Administrator",
+                                               NULL,
                                                get_global_sam_name(),
                                                uid, domadmins_gid);
                shell = talloc_sub_specified(tc, lp_template_shell(),
                                                "Administrator",
+                                               NULL,
                                                get_global_sam_name(),
                                                uid, domadmins_gid);
 
index 688afc627160374e96da0a9f68c92a729b45313d..3b711bd7e18a30cb561de86a00171550bcd523c9 100644 (file)
@@ -214,11 +214,11 @@ static bool fillup_pw_field(const char *lp_template,
 
        if ((in != NULL) && (in[0] != '\0') && (lp_security() == SEC_ADS)) {
                templ = talloc_sub_specified(talloc_tos(), in,
-                                            username, domname,
+                                            username, NULL, domname,
                                             uid, gid);
        } else {
                templ = talloc_sub_specified(talloc_tos(), lp_template,
-                                            username, domname,
+                                            username, NULL, domname,
                                             uid, gid);
        }