lib: Move "iov_buf.[ch]" to lib/util
[obnox/samba/samba-obnox.git] / source3 / lib / substitute.c
index 08cc03eeb275aba1cbc794390435780c6aacdf44..ce4fbbab73d4d915f5816eca4e8d815e7327289b 100644 (file)
@@ -66,7 +66,10 @@ bool set_local_machine_name(const char *local_name, bool perm)
        /* alpha_strcpy includes the space for the terminating nul. */
        alpha_strcpy(local_machine,tmp_local_machine,
                        SAFE_NETBIOS_CHARS,len+1);
-       strlower_m(local_machine);
+       if (!strlower_m(local_machine)) {
+               TALLOC_FREE(tmp_local_machine);
+               return false;
+       }
        TALLOC_FREE(tmp_local_machine);
 
        already_perm = perm;
@@ -118,7 +121,10 @@ bool set_remote_machine_name(const char *remote_name, bool perm)
        /* alpha_strcpy includes the space for the terminating nul. */
        alpha_strcpy(remote_machine,tmp_remote_machine,
                        SAFE_NETBIOS_CHARS,len+1);
-       strlower_m(remote_machine);
+       if (!strlower_m(remote_machine)) {
+               TALLOC_FREE(tmp_remote_machine);
+               return false;
+       }
        TALLOC_FREE(tmp_remote_machine);
 
        already_perm = perm;
@@ -153,7 +159,10 @@ void sub_set_smb_name(const char *name)
                return;
        }
        trim_char(tmp, ' ', ' ');
-       strlower_m(tmp);
+       if (!strlower_m(tmp)) {
+               TALLOC_FREE(tmp);
+               return;
+       }
 
        len = strlen(tmp);
 
@@ -346,7 +355,7 @@ static const char *automount_path(const char *user_name)
 
 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
 
-       if (lp_nis_home_map()) {
+       if (lp_nis_homedir()) {
                const char *home_path_start;
                char *automount_value = automount_lookup(ctx, user_name);
 
@@ -401,7 +410,7 @@ static const char *automount_server(const char *user_name)
        }
 
 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
-       if (lp_nis_home_map()) {
+       if (lp_nis_homedir()) {
                char *p;
                char *srv;
                char *automount_value = automount_lookup(ctx, user_name);
@@ -490,10 +499,20 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx,
                        break;
                case 'G' : {
                        struct passwd *pass;
-                       r = talloc_strdup(tmp_ctx, smb_name);
+
+                       if (domain_name != NULL && domain_name[0] != '\0') {
+                               r = talloc_asprintf(tmp_ctx,
+                                                   "%s%c%s",
+                                                   domain_name,
+                                                   *lp_winbind_separator(),
+                                                   smb_name);
+                       } else {
+                               r = talloc_strdup(tmp_ctx, smb_name);
+                       }
                        if (r == NULL) {
                                goto error;
                        }
+
                        pass = Get_Pwnam_alloc(tmp_ctx, r);
                        if (pass != NULL) {
                                a_string = realloc_string_sub(
@@ -549,7 +568,7 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx,
                                        get_remote_arch_str());
                        break;
                case 'd' :
-                       slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid());
+                       slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)getpid());
                        a_string = realloc_string_sub(a_string, "%d", pidstr);
                        break;
                case 'h' :
@@ -604,6 +623,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)
@@ -639,9 +659,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,
@@ -650,9 +679,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");