Author: vlendec
Date: 2006-06-15 15:24:20 +0000 (Thu, 15 Jun 2006)
New Revision: 16260

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16260

Log:
Replace alloc_sub_specified by talloc_sub_specified, the alloc version was
used in one place only anyway.

Volker


Modified:
   trunk/source/lib/substitute.c
   trunk/source/nsswitch/winbindd_user.c
   trunk/source/script/tests/test_smbtorture_s3.sh
   trunk/source/torture/torture.c


Changeset:
Modified: trunk/source/lib/substitute.c
===================================================================
--- trunk/source/lib/substitute.c       2006-06-15 14:55:40 UTC (rev 16259)
+++ trunk/source/lib/substitute.c       2006-06-15 15:24:20 UTC (rev 16260)
@@ -466,7 +466,7 @@
        
        a_string = SMB_STRDUP(str);
        if (a_string == NULL) {
-               DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));
+               DEBUG(0, ("alloc_sub_basic: Out of memory!\n"));
                return NULL;
        }
        
@@ -583,32 +583,20 @@
                        uid_t uid,
                        gid_t gid)
 {
-       char *a, *t;
-               a = alloc_sub_specified(input_string, username, domain, uid, 
gid);
-       if (!a) {
+       char *a_string;
+       char *ret_string = NULL;
+       char *b, *p, *s;
+       TALLOC_CTX *tmp_ctx;
+
+       if (!(tmp_ctx = talloc_new(mem_ctx))) {
+               DEBUG(0, ("talloc_new failed\n"));
                return NULL;
        }
-       t = talloc_strdup(mem_ctx, a);
-       SAFE_FREE(a);
-       return t;
-}
 
-/****************************************************************************
-****************************************************************************/
-
-char *alloc_sub_specified(const char *input_string,
-                       const char *username,
-                       const char *domain,
-                       uid_t uid,
-                       gid_t gid)
-{
-       char *a_string, *ret_string;
-       char *b, *p, *s;
-
-       a_string = SMB_STRDUP(input_string);
+       a_string = talloc_strdup(tmp_ctx, input_string);
        if (a_string == NULL) {
-               DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));
-               return NULL;
+               DEBUG(0, ("talloc_sub_specified: Out of memory!\n"));
+               goto done;
        }
        
        for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
@@ -617,30 +605,42 @@
                
                switch (*(p+1)) {
                case 'U' : 
-                       a_string = realloc_string_sub(a_string, "%U", username);
+                       a_string = talloc_string_sub(
+                               tmp_ctx, a_string, "%U", username);
                        break;
                case 'u' : 
-                       a_string = realloc_string_sub(a_string, "%u", username);
+                       a_string = talloc_string_sub(
+                               tmp_ctx, a_string, "%u", username);
                        break;
                case 'G' :
                        if (gid != -1) {
-                               a_string = realloc_string_sub(a_string, "%G", 
gidtoname(gid));
+                               a_string = talloc_string_sub(
+                                       tmp_ctx, a_string, "%G",
+                                       gidtoname(gid));
                        } else {
-                               a_string = realloc_string_sub(a_string, "%G", 
"NO_GROUP");
+                               a_string = talloc_string_sub(
+                                       tmp_ctx, a_string,
+                                       "%G", "NO_GROUP");
                        }
                        break;
                case 'g' :
                        if (gid != -1) {
-                               a_string = realloc_string_sub(a_string, "%g", 
gidtoname(gid));
+                               a_string = talloc_string_sub(
+                                       tmp_ctx, a_string, "%g",
+                                       gidtoname(gid));
                        } else {
-                               a_string = realloc_string_sub(a_string, "%g", 
"NO_GROUP");
+                               a_string = talloc_string_sub(
+                                       tmp_ctx, a_string, "%g", "NO_GROUP");
                        }
                        break;
                case 'D' :
-                       a_string = realloc_string_sub(a_string, "%D", domain);
+                       a_string = talloc_string_sub(tmp_ctx, a_string,
+                                                    "%D", domain);
                        break;
                case 'N' : 
-                       a_string = realloc_string_sub(a_string, "%N", 
automount_server(username)); 
+                       a_string = talloc_string_sub(
+                               tmp_ctx, a_string, "%N",
+                               automount_server(username)); 
                        break;
                default: 
                        break;
@@ -648,13 +648,17 @@
 
                p++;
                if (a_string == NULL) {
-                       return NULL;
+                       goto done;
                }
        }
 
-       ret_string = alloc_sub_basic(username, current_user_info.domain,
-                                    a_string);
-       SAFE_FREE(a_string);
+       /* Watch out, using "mem_ctx" here, so all intermediate stuff goes
+        * away with the TALLOC_FREE(tmp_ctx) further down. */
+
+       ret_string = talloc_sub_basic(mem_ctx, username, domain, a_string);
+
+ done:
+       TALLOC_FREE(tmp_ctx);
        return ret_string;
 }
 

Modified: trunk/source/nsswitch/winbindd_user.c
===================================================================
--- trunk/source/nsswitch/winbindd_user.c       2006-06-15 14:55:40 UTC (rev 
16259)
+++ trunk/source/nsswitch/winbindd_user.c       2006-06-15 15:24:20 UTC (rev 
16260)
@@ -53,13 +53,14 @@
        /* The substitution of %U and %D in the 'template homedir' is done
           by alloc_sub_specified() below. */
 
-       templ = alloc_sub_specified(lp_template, username, domname, uid, gid);
+       templ = talloc_sub_specified(NULL, lp_template, username, domname,
+                                    uid, gid);
                
        if (!templ)
                return False;
 
        safe_strcpy(out, templ, sizeof(fstring) - 1);
-       SAFE_FREE(templ);
+       TALLOC_FREE(templ);
                
        return True;
        

Modified: trunk/source/script/tests/test_smbtorture_s3.sh
===================================================================
--- trunk/source/script/tests/test_smbtorture_s3.sh     2006-06-15 14:55:40 UTC 
(rev 16259)
+++ trunk/source/script/tests/test_smbtorture_s3.sh     2006-06-15 15:24:20 UTC 
(rev 16260)
@@ -24,7 +24,7 @@
 tests="$tests OPLOCK1 OPLOCK2 OPLOCK3"
 tests="$tests DIR DIR1 TCON TCONDEV RW1 RW2 RW3"
 tests="$tests OPEN XCOPY RENAME DELETE PROPERTIES W2K"
-tests="$tests PIPE_NUMBER TCON2 IOCTL CHKPATH FDSESS"
+tests="$tests PIPE_NUMBER TCON2 IOCTL CHKPATH FDSESS LOCAL-SUBSTITUTE"
 
 skipped1="RANDOMIPC NEGNOWAIT NBENCH ERRMAPEXTRACT TRANS2SCAN NTTRANSSCAN"
 skipped2="DENY1 DENY2 OPENATTR CASETABLE EATEST"

Modified: trunk/source/torture/torture.c
===================================================================
--- trunk/source/torture/torture.c      2006-06-15 14:55:40 UTC (rev 16259)
+++ trunk/source/torture/torture.c      2006-06-15 15:24:20 UTC (rev 16260)
@@ -493,7 +493,7 @@
                        printf("%d\r", i); fflush(stdout);
                }
 
-               generate_random_buffer(buf, buf_size);
+               generate_random_buffer((unsigned char *)buf, buf_size);
 
                if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
                        printf("write failed (%s)\n", cli_errstr(c1));
@@ -2201,7 +2201,7 @@
 {
        char *rparam = NULL;
        char *rdata = NULL;
-       int rdrcnt,rprcnt;
+       unsigned int rdrcnt,rprcnt;
        pstring param;
        int api, param_len, i;
        struct cli_state *cli;
@@ -4417,7 +4417,8 @@
 
        for (i = 0; i < num_eas; i++) {
                printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
-               dump_data(0, ea_list[i].value.data, ea_list[i].value.length);
+               dump_data(0, (char *)ea_list[i].value.data,
+                         ea_list[i].value.length);
        }
 
        /* Setting EA's to zero length deletes them. Test this */
@@ -4444,7 +4445,8 @@
        printf("num_eas = %d\n", num_eas);
        for (i = 0; i < num_eas; i++) {
                printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
-               dump_data(0, ea_list[i].value.data, ea_list[i].value.length);
+               dump_data(0, (char *)ea_list[i].value.data,
+                         ea_list[i].value.length);
        }
 
        if (num_eas != 0) {
@@ -4654,6 +4656,42 @@
        return True;
 }
 
+static BOOL run_local_substitute(int dummy)
+{
+       TALLOC_CTX *mem_ctx;
+       int diff = 0;
+
+       if ((mem_ctx = talloc_init("run_local_subst")) == NULL) {
+               printf("talloc_init failed\n");
+               return False;
+       }
+
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%U", "bla", "", -1, -1),
+                      "bla");
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%u%U", "bla", "", -1, -1),
+                      "blabla");
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, -1),
+                      "NO_GROUP");
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, -1),
+                      "NO_GROUP");
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, 0),
+                      gidtoname(0));
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, 0),
+                      gidtoname(0));
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%D%u", "u", "dom", -1, 0),
+                      "domu");
+       diff |= strcmp(talloc_sub_specified(mem_ctx, "%i %I", "", "", -1, -1),
+                      "0.0.0.0 0.0.0.0");
+
+       /* Different captialization rules in sub_basic... */
+
+       diff |= strcmp(talloc_sub_basic(mem_ctx, "BLA", "dom", "%U%D"),
+                      "blaDOM");
+
+       TALLOC_FREE(mem_ctx);
+       return (diff == 0);
+}
+
 static double create_procs(BOOL (*fn)(int), BOOL *result)
 {
        int i, status;
@@ -4804,6 +4842,7 @@
        {"CHKPATH",  torture_chkpath_test, 0},
        {"FDSESS", run_fdsesstest, 0},
        { "EATEST", run_eatest, 0},
+       { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        {NULL, NULL, 0}};
 
 

Reply via email to