Author: jra
Date: 2007-09-14 22:14:39 +0000 (Fri, 14 Sep 2007)
New Revision: 25171

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

Log:
More pstring removal.
Jeremy.

Modified:
   branches/SAMBA_3_2/source/lib/adt_tree.c
   branches/SAMBA_3_2/source/lib/smbrun.c
   branches/SAMBA_3_2_0/source/lib/adt_tree.c
   branches/SAMBA_3_2_0/source/lib/smbrun.c


Changeset:
Modified: branches/SAMBA_3_2/source/lib/adt_tree.c
===================================================================
--- branches/SAMBA_3_2/source/lib/adt_tree.c    2007-09-14 22:03:41 UTC (rev 
25170)
+++ branches/SAMBA_3_2/source/lib/adt_tree.c    2007-09-14 22:14:39 UTC (rev 
25171)
@@ -278,31 +278,41 @@
  Recursive routine to print out all children of a TREE_NODE
  *************************************************************************/
 
-static void pathtree_print_children( TREE_NODE *node, int debug, const char 
*path )
+static void pathtree_print_children(TALLOC_CTX *ctx,
+                               TREE_NODE *node,
+                               int debug,
+                               const char *path )
 {
        int i;
        int num_children;
-       pstring path2;
-       
+       char *path2 = NULL;
+
        if ( !node )
                return;
-       
-       
+
        if ( node->key )
                DEBUG(debug,("%s: [%s] (%s)\n", path ? path : "NULL", node->key,
                        node->data_p ? "data" : "NULL" ));
 
-       *path2 = '\0';
-       if ( path )
-               pstrcpy( path2, path );
-       pstrcat( path2, node->key ? node->key : "NULL" );
-       pstrcat( path2, "/" );
-               
+       if ( path ) {
+               path2 = talloc_strdup(ctx, path);
+               if (!path2) {
+                       return;
+               }
+       }
+
+       path2 = talloc_asprintf(ctx,
+                       "%s%s/",
+                       path ? path : "",
+                       node->key ? node->key : "NULL");
+       if (!path2) {
+               return;
+       }
+
        num_children = node->num_children;
-       for ( i=0; i<num_children; i++ )
-               pathtree_print_children( node->children[i], debug, path2 );
-       
-
+       for ( i=0; i<num_children; i++ ) {
+               pathtree_print_children(ctx, node->children[i], debug, path2 );
+       }
 }
 
 /**************************************************************************
@@ -313,21 +323,23 @@
 {
        int i;
        int num_children = tree->root->num_children;
-       
+
        if ( tree->root->key )
                DEBUG(debug,("ROOT/: [%s] (%s)\n", tree->root->key,
                        tree->root->data_p ? "data" : "NULL" ));
-       
+
        for ( i=0; i<num_children; i++ ) {
-               pathtree_print_children( tree->root->children[i], debug, 
+               TALLOC_CTX *ctx = talloc_stackframe();
+               pathtree_print_children(ctx, tree->root->children[i], debug,
                        tree->root->key ? tree->root->key : "ROOT/" );
+               TALLOC_FREE(ctx);
        }
-       
+
 }
 
 /**************************************************************************
  return the data_p for for the node in tree matching the key string
- The key string is the full path.  We must break it apart and walk 
+ The key string is the full path.  We must break it apart and walk
  the tree
  *************************************************************************/
 

Modified: branches/SAMBA_3_2/source/lib/smbrun.c
===================================================================
--- branches/SAMBA_3_2/source/lib/smbrun.c      2007-09-14 22:03:41 UTC (rev 
25170)
+++ branches/SAMBA_3_2/source/lib/smbrun.c      2007-09-14 22:14:39 UTC (rev 
25171)
@@ -1,18 +1,18 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    run a command as a specified user
    Copyright (C) Andrew Tridgell 1992-1998
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -27,11 +27,19 @@
 ****************************************************************************/
 
 static int setup_out_fd(void)
-{  
+{
        int fd;
-       pstring path;
+       TALLOC_CTX *ctx = talloc_stackframe();
+       char *path = NULL;
 
-       slprintf(path, sizeof(path)-1, "%s/smb.XXXXXX", tmpdir());
+       path = talloc_asprintf(ctx,
+                               "%s/smb.XXXXXX",
+                               tmpdir());
+       if (!path) {
+               TALLOC_FREE(ctx);
+               errno = ENOMEM;
+               return -1;
+       }
 
        /* now create the file */
        fd = smb_mkstemp(path);
@@ -39,6 +47,7 @@
        if (fd == -1) {
                DEBUG(0,("setup_out_fd: Failed to create file %s. (%s)\n",
                        path, strerror(errno) ));
+               TALLOC_FREE(ctx);
                return -1;
        }
 
@@ -46,6 +55,7 @@
 
        /* Ensure file only kept around by open fd. */
        unlink(path);
+       TALLOC_FREE(ctx);
        return fd;
 }
 
@@ -59,7 +69,7 @@
        pid_t pid;
        uid_t uid = current_user.ut.uid;
        gid_t gid = current_user.ut.gid;
-       
+
        /*
         * Lose any elevated privileges.
         */

Modified: branches/SAMBA_3_2_0/source/lib/adt_tree.c
===================================================================
--- branches/SAMBA_3_2_0/source/lib/adt_tree.c  2007-09-14 22:03:41 UTC (rev 
25170)
+++ branches/SAMBA_3_2_0/source/lib/adt_tree.c  2007-09-14 22:14:39 UTC (rev 
25171)
@@ -278,31 +278,41 @@
  Recursive routine to print out all children of a TREE_NODE
  *************************************************************************/
 
-static void pathtree_print_children( TREE_NODE *node, int debug, const char 
*path )
+static void pathtree_print_children(TALLOC_CTX *ctx,
+                               TREE_NODE *node,
+                               int debug,
+                               const char *path )
 {
        int i;
        int num_children;
-       pstring path2;
-       
+       char *path2 = NULL;
+
        if ( !node )
                return;
-       
-       
+
        if ( node->key )
                DEBUG(debug,("%s: [%s] (%s)\n", path ? path : "NULL", node->key,
                        node->data_p ? "data" : "NULL" ));
 
-       *path2 = '\0';
-       if ( path )
-               pstrcpy( path2, path );
-       pstrcat( path2, node->key ? node->key : "NULL" );
-       pstrcat( path2, "/" );
-               
+       if ( path ) {
+               path2 = talloc_strdup(ctx, path);
+               if (!path2) {
+                       return;
+               }
+       }
+
+       path2 = talloc_asprintf(ctx,
+                       "%s%s/",
+                       path ? path : "",
+                       node->key ? node->key : "NULL");
+       if (!path2) {
+               return;
+       }
+
        num_children = node->num_children;
-       for ( i=0; i<num_children; i++ )
-               pathtree_print_children( node->children[i], debug, path2 );
-       
-
+       for ( i=0; i<num_children; i++ ) {
+               pathtree_print_children(ctx, node->children[i], debug, path2 );
+       }
 }
 
 /**************************************************************************
@@ -313,21 +323,23 @@
 {
        int i;
        int num_children = tree->root->num_children;
-       
+
        if ( tree->root->key )
                DEBUG(debug,("ROOT/: [%s] (%s)\n", tree->root->key,
                        tree->root->data_p ? "data" : "NULL" ));
-       
+
        for ( i=0; i<num_children; i++ ) {
-               pathtree_print_children( tree->root->children[i], debug, 
+               TALLOC_CTX *ctx = talloc_stackframe();
+               pathtree_print_children(ctx, tree->root->children[i], debug,
                        tree->root->key ? tree->root->key : "ROOT/" );
+               TALLOC_FREE(ctx);
        }
-       
+
 }
 
 /**************************************************************************
  return the data_p for for the node in tree matching the key string
- The key string is the full path.  We must break it apart and walk 
+ The key string is the full path.  We must break it apart and walk
  the tree
  *************************************************************************/
 

Modified: branches/SAMBA_3_2_0/source/lib/smbrun.c
===================================================================
--- branches/SAMBA_3_2_0/source/lib/smbrun.c    2007-09-14 22:03:41 UTC (rev 
25170)
+++ branches/SAMBA_3_2_0/source/lib/smbrun.c    2007-09-14 22:14:39 UTC (rev 
25171)
@@ -1,18 +1,18 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    run a command as a specified user
    Copyright (C) Andrew Tridgell 1992-1998
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -27,11 +27,19 @@
 ****************************************************************************/
 
 static int setup_out_fd(void)
-{  
+{
        int fd;
-       pstring path;
+       TALLOC_CTX *ctx = talloc_stackframe();
+       char *path = NULL;
 
-       slprintf(path, sizeof(path)-1, "%s/smb.XXXXXX", tmpdir());
+       path = talloc_asprintf(ctx,
+                               "%s/smb.XXXXXX",
+                               tmpdir());
+       if (!path) {
+               TALLOC_FREE(ctx);
+               errno = ENOMEM;
+               return -1;
+       }
 
        /* now create the file */
        fd = smb_mkstemp(path);
@@ -39,6 +47,7 @@
        if (fd == -1) {
                DEBUG(0,("setup_out_fd: Failed to create file %s. (%s)\n",
                        path, strerror(errno) ));
+               TALLOC_FREE(ctx);
                return -1;
        }
 
@@ -46,6 +55,7 @@
 
        /* Ensure file only kept around by open fd. */
        unlink(path);
+       TALLOC_FREE(ctx);
        return fd;
 }
 
@@ -59,7 +69,7 @@
        pid_t pid;
        uid_t uid = current_user.ut.uid;
        gid_t gid = current_user.ut.gid;
-       
+
        /*
         * Lose any elevated privileges.
         */

Reply via email to