r24949: Remove some static buffers
authorVolker Lendecke <vlendec@samba.org>
Tue, 4 Sep 2007 10:15:04 +0000 (10:15 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:30:29 +0000 (12:30 -0500)
(This used to be commit df648d47ff3c4e24f439fda839653bda98323100)

source3/lib/substitute.c
source3/lib/time.c
source3/lib/util.c
source3/registry/reg_objects.c
source3/registry/reg_perfcount.c
source3/registry/reg_util.c
source3/rpc_client/cli_svcctl.c
source3/services/services_db.c
source3/smbd/lanman.c

index 64b343fabbfaa9f5024466916d27096fee4c5037..955557f40cf6a56bb0da5dbd17ef033345fe03f0 100644 (file)
@@ -263,7 +263,7 @@ struct api_longvar {
        char* (*fn)( void );
 };
 
        char* (*fn)( void );
 };
 
-struct api_longvar longvar_table[] = {
+static struct api_longvar longvar_table[] = {
        { "DomainSID",          longvar_domainsid },
        { NULL,                 NULL }
 };
        { "DomainSID",          longvar_domainsid },
        { NULL,                 NULL }
 };
@@ -339,7 +339,7 @@ static char *realloc_expand_longvar(char *str, char *p)
 
 static char *automount_path(const char *user_name)
 {
 
 static char *automount_path(const char *user_name)
 {
-       static pstring server_path;
+       pstring server_path;
 
        /* use the passwd entry as the default */
        /* this will be the default if WITH_AUTOMOUNT is not used or fails */
 
        /* use the passwd entry as the default */
        /* this will be the default if WITH_AUTOMOUNT is not used or fails */
@@ -368,7 +368,7 @@ static char *automount_path(const char *user_name)
 
        DEBUG(4,("Home server path: %s\n", server_path));
 
 
        DEBUG(4,("Home server path: %s\n", server_path));
 
-       return server_path;
+       return talloc_strdup(talloc_tos(), server_path);
 }
 
 /*******************************************************************
 }
 
 /*******************************************************************
@@ -379,7 +379,7 @@ static char *automount_path(const char *user_name)
 
 static const char *automount_server(const char *user_name)
 {
 
 static const char *automount_server(const char *user_name)
 {
-       static pstring server_name;
+       pstring server_name;
        const char *local_machine_name = get_local_machine_name(); 
 
        /* use the local machine name as the default */
        const char *local_machine_name = get_local_machine_name(); 
 
        /* use the local machine name as the default */
@@ -405,7 +405,7 @@ static const char *automount_server(const char *user_name)
 
        DEBUG(4,("Home server: %s\n", server_name));
 
 
        DEBUG(4,("Home server: %s\n", server_name));
 
-       return server_name;
+       return talloc_strdup(talloc_tos(), server_name);
 }
 
 /****************************************************************************
 }
 
 /****************************************************************************
index 9d874c21fa62aa4c07bc4173a2973454c1686656..35d10186be91b5bfcbacbad60a8da54c092bedbd 100644 (file)
@@ -303,13 +303,13 @@ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset)
 
 char *http_timestring(time_t t)
 {
 
 char *http_timestring(time_t t)
 {
-       static fstring buf;
+       fstring buf;
        struct tm *tm = localtime(&t);
 
        if (t == TIME_T_MAX) {
        struct tm *tm = localtime(&t);
 
        if (t == TIME_T_MAX) {
-               slprintf(buf,sizeof(buf)-1,"never");
+               fstrcpy(buf, "never");
        } else if (!tm) {
        } else if (!tm) {
-               slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t);
+               fstr_sprintf(buf, "%ld seconds since the Epoch", (long)t);
        } else {
 #ifndef HAVE_STRFTIME
                const char *asct = asctime(tm);
        } else {
 #ifndef HAVE_STRFTIME
                const char *asct = asctime(tm);
@@ -321,7 +321,7 @@ char *http_timestring(time_t t)
                strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
 #endif /* !HAVE_STRFTIME */
        }
                strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
 #endif /* !HAVE_STRFTIME */
        }
-       return buf;
+       return talloc_strdup(talloc_tos(), buf);
 }
 
 
 }
 
 
@@ -689,7 +689,7 @@ int set_server_zone_offset(time_t t)
 
 char *current_timestring(BOOL hires)
 {
 
 char *current_timestring(BOOL hires)
 {
-       static fstring TimeBuf;
+       fstring TimeBuf;
        struct timeval tp;
        time_t t;
        struct tm *tm;
        struct timeval tp;
        time_t t;
        struct tm *tm;
@@ -739,7 +739,7 @@ char *current_timestring(BOOL hires)
                }
 #endif
        }
                }
 #endif
        }
-       return(TimeBuf);
+       return talloc_strdup(talloc_tos(), TimeBuf);
 }
 
 
 }
 
 
@@ -1423,8 +1423,6 @@ const char *time_to_asc(const time_t t)
 
 const char *display_time(NTTIME nttime)
 {
 
 const char *display_time(NTTIME nttime)
 {
-       static fstring string;
-
        float high;
        float low;
        int sec;
        float high;
        float low;
        int sec;
@@ -1452,8 +1450,8 @@ const char *display_time(NTTIME nttime)
        mins=(sec - (days*60*60*24) - (hours*60*60) ) / 60;
        secs=sec - (days*60*60*24) - (hours*60*60) - (mins*60);
 
        mins=(sec - (days*60*60*24) - (hours*60*60) ) / 60;
        secs=sec - (days*60*60*24) - (hours*60*60) - (mins*60);
 
-       fstr_sprintf(string, "%u days, %u hours, %u minutes, %u seconds", days, hours, mins, secs);
-       return (string);
+       return talloc_asprintf(talloc_tos(), "%u days, %u hours, %u minutes, "
+                              "%u seconds", days, hours, mins, secs);
 }
 
 BOOL nt_time_is_set(const NTTIME *nt)
 }
 
 BOOL nt_time_is_set(const NTTIME *nt)
index 3852fccdd1e6ab75bde00ded7c2a41c82272677e..5314239e07ce6d4c5e180035596d26823951da65 100644 (file)
@@ -456,7 +456,7 @@ SMB_OFF_T get_file_size(char *file_name)
 
 char *attrib_string(uint16 mode)
 {
 
 char *attrib_string(uint16 mode)
 {
-       static fstring attrstr;
+       fstring attrstr;
 
        attrstr[0] = 0;
 
 
        attrstr[0] = 0;
 
@@ -467,7 +467,7 @@ char *attrib_string(uint16 mode)
        if (mode & aSYSTEM) fstrcat(attrstr,"S");
        if (mode & aRONLY) fstrcat(attrstr,"R");          
 
        if (mode & aSYSTEM) fstrcat(attrstr,"S");
        if (mode & aRONLY) fstrcat(attrstr,"R");          
 
-       return(attrstr);
+       return talloc_strdup(talloc_tos(), attrstr);
 }
 
 /*******************************************************************
 }
 
 /*******************************************************************
@@ -1578,17 +1578,17 @@ BOOL process_exists_by_pid(pid_t pid)
 
 const char *uidtoname(uid_t uid)
 {
 
 const char *uidtoname(uid_t uid)
 {
-       static fstring name;
+       fstring name;
        struct passwd *pass;
 
        struct passwd *pass;
 
-       pass = getpwuid_alloc(NULL, uid);
+       pass = getpwuid_alloc(talloc_tos(), uid);
        if (pass) {
                fstrcpy(name, pass->pw_name);
                TALLOC_FREE(pass);
        } else {
                slprintf(name, sizeof(name) - 1, "%ld",(long int)uid);
        }
        if (pass) {
                fstrcpy(name, pass->pw_name);
                TALLOC_FREE(pass);
        } else {
                slprintf(name, sizeof(name) - 1, "%ld",(long int)uid);
        }
-       return name;
+       return talloc_strdup(talloc_tos(), name);
 }
 
 
 }
 
 
@@ -1598,14 +1598,17 @@ const char *uidtoname(uid_t uid)
 
 char *gidtoname(gid_t gid)
 {
 
 char *gidtoname(gid_t gid)
 {
-       static fstring name;
+       fstring name;
        struct group *grp;
 
        grp = getgrgid(gid);
        struct group *grp;
 
        grp = getgrgid(gid);
-       if (grp)
-               return(grp->gr_name);
-       slprintf(name,sizeof(name) - 1, "%d",(int)gid);
-       return(name);
+       if (grp) {
+               fstrcpy(name, grp->gr_name);
+       }
+       else {
+               slprintf(name,sizeof(name) - 1, "%d",(int)gid);
+       }
+       return talloc_strdup(talloc_tos(), name);
 }
 
 /*******************************************************************
 }
 
 /*******************************************************************
@@ -1859,15 +1862,7 @@ const char *readdirname(SMB_STRUCT_DIR *p)
        dname = dname - 2;
 #endif
 
        dname = dname - 2;
 #endif
 
-       {
-               static pstring buf;
-               int len = NAMLEN(ptr);
-               memcpy(buf, dname, len);
-               buf[len] = 0;
-               dname = buf;
-       }
-
-       return(dname);
+       return talloc_strdup(talloc_tos(), dname);
 }
 
 /*******************************************************************
 }
 
 /*******************************************************************
@@ -2629,7 +2624,7 @@ char *myhostname(void)
 
 char *lock_path(const char *name)
 {
 
 char *lock_path(const char *name)
 {
-       static pstring fname;
+       pstring fname;
 
        pstrcpy(fname,lp_lockdir());
        trim_char(fname,'\0','/');
 
        pstrcpy(fname,lp_lockdir());
        trim_char(fname,'\0','/');
@@ -2640,7 +2635,7 @@ char *lock_path(const char *name)
        pstrcat(fname,"/");
        pstrcat(fname,name);
 
        pstrcat(fname,"/");
        pstrcat(fname,name);
 
-       return fname;
+       return talloc_strdup(talloc_tos(), fname);
 }
 
 /*****************************************************************
 }
 
 /*****************************************************************
@@ -2649,7 +2644,7 @@ char *lock_path(const char *name)
 
 char *pid_path(const char *name)
 {
 
 char *pid_path(const char *name)
 {
-       static pstring fname;
+       pstring fname;
 
        pstrcpy(fname,lp_piddir());
        trim_char(fname,'\0','/');
 
        pstrcpy(fname,lp_piddir());
        trim_char(fname,'\0','/');
@@ -2660,7 +2655,7 @@ char *pid_path(const char *name)
        pstrcat(fname,"/");
        pstrcat(fname,name);
 
        pstrcat(fname,"/");
        pstrcat(fname,name);
 
-       return fname;
+       return talloc_strdup(talloc_tos(), fname);
 }
 
 /**
 }
 
 /**
@@ -2673,9 +2668,7 @@ char *pid_path(const char *name)
 
 char *lib_path(const char *name)
 {
 
 char *lib_path(const char *name)
 {
-       static pstring fname;
-       fstr_sprintf(fname, "%s/%s", dyn_LIBDIR, name);
-       return fname;
+       return talloc_asprintf(talloc_tos(), "%s/%s", dyn_LIBDIR, name);
 }
 
 /**
 }
 
 /**
@@ -2692,29 +2685,18 @@ const char *shlib_ext(void)
 /*******************************************************************
  Given a filename - get its directory name
  NB: Returned in static storage.  Caveats:
 /*******************************************************************
  Given a filename - get its directory name
  NB: Returned in static storage.  Caveats:
- o  Not safe in thread environment.
- o  Caller must not free.
  o  If caller wishes to preserve, they should copy.
 ********************************************************************/
 
 char *parent_dirname(const char *path)
 {
  o  If caller wishes to preserve, they should copy.
 ********************************************************************/
 
 char *parent_dirname(const char *path)
 {
-       static pstring dirpath;
-       char *p;
-
-       if (!path)
-               return(NULL);
+       char *parent;
 
 
-       pstrcpy(dirpath, path);
-       p = strrchr_m(dirpath, '/');  /* Find final '/', if any */
-       if (!p) {
-               pstrcpy(dirpath, ".");    /* No final "/", so dir is "." */
-       } else {
-               if (p == dirpath)
-                       ++p;    /* For root "/", leave "/" in place */
-               *p = '\0';
+       if (!parent_dirname_talloc(talloc_tos(), path, &parent, NULL)) {
+               return NULL;
        }
        }
-       return dirpath;
+
+       return parent;
 }
 
 BOOL parent_dirname_talloc(TALLOC_CTX *mem_ctx, const char *dir,
 }
 
 BOOL parent_dirname_talloc(TALLOC_CTX *mem_ctx, const char *dir,
@@ -3179,9 +3161,9 @@ struct server_id interpret_pid(const char *pid_string)
 #endif
 }
 
 #endif
 }
 
-char *procid_str_static(const struct server_id *pid)
+char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
 {
 {
-       static fstring str;
+       fstring str;
 #ifdef CLUSTER_SUPPORT
        if (pid->vnn == NONCLUSTER_VNN) {
                fstr_sprintf(str, "%d", (int)pid->pid);
 #ifdef CLUSTER_SUPPORT
        if (pid->vnn == NONCLUSTER_VNN) {
                fstr_sprintf(str, "%d", (int)pid->pid);
@@ -3192,12 +3174,12 @@ char *procid_str_static(const struct server_id *pid)
 #else
        fstr_sprintf(str, "%d", (int)pid->pid);
 #endif
 #else
        fstr_sprintf(str, "%d", (int)pid->pid);
 #endif
-       return str;
+       return talloc_strdup(mem_ctx, str);
 }
 
 }
 
-char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
+char *procid_str_static(const struct server_id *pid)
 {
 {
-       return talloc_strdup(mem_ctx, procid_str_static(pid));
+       return procid_str(talloc_tos(), pid);
 }
 
 BOOL procid_valid(const struct server_id *pid)
 }
 
 BOOL procid_valid(const struct server_id *pid)
index aebf0142eec15a2fa55e7c1689e579d63593916a..f759a921d23530965c6202f76b66e26408c60f6e 100644 (file)
@@ -439,9 +439,9 @@ uint32 regval_dword( REGISTRY_VALUE *val )
 
 char* regval_sz( REGISTRY_VALUE *val )
 {
 
 char* regval_sz( REGISTRY_VALUE *val )
 {
-       static pstring data;
+       pstring data;
 
        rpcstr_pull( data, regval_data_p(val), sizeof(data), regval_size(val), 0 );
        
 
        rpcstr_pull( data, regval_data_p(val), sizeof(data), regval_size(val), 0 );
        
-       return data;
+       return talloc_strdup(talloc_tos(), data);
 }
 }
index dec57a5ec78130a928ad6fccbd6bea399a482208..ce67b68a8357e31c827bebc4055ef9f5f05e073f 100644 (file)
@@ -37,7 +37,7 @@ PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind);
 
 static char* counters_directory( const char *dbname )
 {
 
 static char* counters_directory( const char *dbname )
 {
-       static pstring fname;
+       pstring fname;
        fstring path;
        
        if ( !dbname )
        fstring path;
        
        if ( !dbname )
@@ -47,7 +47,7 @@ static char* counters_directory( const char *dbname )
        
        pstrcpy( fname, lock_path( path ) );
        
        
        pstrcpy( fname, lock_path( path ) );
        
-       return fname;
+       return talloc_strdup(talloc_tos(), fname);
 }
 
 /*********************************************************************
 }
 
 /*********************************************************************
index 75050c185006afb75dc1f8c0841c5619c8306b8e..703ad7cb57de382022da7019c2efd146652b5017 100644 (file)
@@ -102,7 +102,7 @@ void normalize_reg_path( pstring keyname )
 
 char* reg_remaining_path( const char *key )
 {
 
 char* reg_remaining_path( const char *key )
 {
-       static pstring new_path;
+       pstring new_path;
        char *p;
        
        if ( !key || !*key )
        char *p;
        
        if ( !key || !*key )
@@ -121,7 +121,7 @@ char* reg_remaining_path( const char *key )
        else
                p++;
                
        else
                p++;
                
-       return p;
+       return talloc_strdup(talloc_tos(), p);
 }
 
 /**********************************************************************
 }
 
 /**********************************************************************
index cb016cbd146ab35946b87684d30976dce7e69c71..95673c15654f53bbc491ac0e0b39f47890aa698e 100644 (file)
@@ -42,7 +42,7 @@ static struct svc_state_msg state_msg_table[] = {
 ********************************************************************/
 const char* svc_status_string( uint32 state )
 {
 ********************************************************************/
 const char* svc_status_string( uint32 state )
 {
-       static fstring msg;
+       fstring msg;
        int i;
        
        fstr_sprintf( msg, "Unknown State [%d]", state );
        int i;
        
        fstr_sprintf( msg, "Unknown State [%d]", state );
@@ -54,7 +54,7 @@ const char* svc_status_string( uint32 state )
                }
        }
        
                }
        }
        
-       return msg;
+       return talloc_strdup(talloc_tos(), msg);
 }
 
 /********************************************************************
 }
 
 /********************************************************************
index 6811db4b14a4dfb19f0c3f44864799ff5ccf0130..f3ec62a01b06bf205ba4f67318041eedf95294f4 100644 (file)
@@ -148,7 +148,7 @@ static char *get_common_service_dispname( const char *servicename )
 
 static char* cleanup_string( const char *string )
 {
 
 static char* cleanup_string( const char *string )
 {
-       static pstring clean;
+       pstring clean;
        char *begin, *end;
 
        pstrcpy( clean, string );
        char *begin, *end;
 
        pstrcpy( clean, string );
@@ -172,7 +172,7 @@ static char* cleanup_string( const char *string )
                end--;
        }
 
                end--;
        }
 
-       return begin;
+       return talloc_strdup(talloc_tos(), begin);
 }
 
 /********************************************************************
 }
 
 /********************************************************************
index 581ac90aeb611f063b1328af4f27fccfe98633cc..9eb2a283cc1aef20b67539138680ce41c3e5b10b 100644 (file)
@@ -116,18 +116,16 @@ static int StrlenExpanded(connection_struct *conn, int snum, char *s)
 
 static char *Expand(connection_struct *conn, int snum, char *s)
 {
 
 static char *Expand(connection_struct *conn, int snum, char *s)
 {
-       static pstring buf;
+       pstring buf;
        if (!s) {
                return NULL;
        }
        StrnCpy(buf,s,sizeof(buf)/2);
        pstring_sub(buf,"%S",lp_servicename(snum));
        if (!s) {
                return NULL;
        }
        StrnCpy(buf,s,sizeof(buf)/2);
        pstring_sub(buf,"%S",lp_servicename(snum));
-       standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user,
-                             conn->connectpath, conn->gid,
-                             get_current_username(),
-                             current_user_info.domain,
-                             buf, sizeof(buf));
-       return &buf[0];
+       return talloc_sub_advanced(talloc_tos(), lp_servicename(SNUM(conn)),
+                                  conn->user, conn->connectpath, conn->gid,
+                                  get_current_username(),
+                                  current_user_info.domain, buf);
 }
 
 /*******************************************************************
 }
 
 /*******************************************************************