[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / lib / substitute.c
index 430c8029b8f812b669f64631956534d4355061d0..57df02f7216f7b7a7141104ecaaf6f30368e5b77 100644 (file)
@@ -6,7 +6,7 @@
    
    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 2 of the License, or
+   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,
@@ -15,8 +15,7 @@
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 
@@ -141,11 +140,6 @@ void sub_set_smb_name(const char *name)
        }
 }
 
-char* sub_get_smb_name( void )
-{
-       return smb_user_name;
-}
-
 /*******************************************************************
  Setup the strings used by substitutions. Called per packet. Ensure
  %U name is set correctly also.
@@ -155,7 +149,7 @@ void set_current_user_info(const userdom_struct *pcui)
 {
        current_user_info = *pcui;
        /* The following is safe as current_user_info.smb_name
-        * has already been sanitised in register_vuid. */
+        * has already been sanitised in register_existing_vuid. */
        fstrcpy(smb_user_name, current_user_info.smb_name);
 }
 
@@ -264,7 +258,7 @@ struct api_longvar {
        char* (*fn)( void );
 };
 
-struct api_longvar longvar_table[] = {
+static struct api_longvar longvar_table[] = {
        { "DomainSID",          longvar_domainsid },
        { NULL,                 NULL }
 };
@@ -340,7 +334,7 @@ static char *realloc_expand_longvar(char *str, char *p)
 
 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 */
@@ -369,7 +363,7 @@ static char *automount_path(const char *user_name)
 
        DEBUG(4,("Home server path: %s\n", server_path));
 
-       return server_path;
+       return talloc_strdup(talloc_tos(), server_path);
 }
 
 /*******************************************************************
@@ -380,7 +374,7 @@ static char *automount_path(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 */
@@ -406,7 +400,7 @@ static const char *automount_server(const char *user_name)
 
        DEBUG(4,("Home server: %s\n", server_name));
 
-       return server_name;
+       return talloc_strdup(talloc_tos(), server_name);
 }
 
 /****************************************************************************
@@ -453,7 +447,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
                      const char *str)
 {
        char *b, *p, *s, *r, *a_string;
-       fstring pidstr;
+       fstring pidstr, vnnstr;
        struct passwd *pass;
        const char *local_machine_name = get_local_machine_name();
 
@@ -552,6 +546,10 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
                case '(':
                        a_string = realloc_expand_longvar( a_string, p );
                        break;
+               case 'V' :
+                       slprintf(vnnstr,sizeof(vnnstr)-1, "%u", get_my_vnn());
+                       a_string = realloc_string_sub(a_string, "%V", vnnstr);
+                       break;
                default: 
                        break;
                }
@@ -665,7 +663,7 @@ char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
 /****************************************************************************
 ****************************************************************************/
 
-char *alloc_sub_advanced(const char *servicename, const char *user, 
+static char *alloc_sub_advanced(const char *servicename, const char *user, 
                         const char *connectpath, gid_t gid, 
                         const char *smb_name, const char *domain_name,
                         const char *str)
@@ -731,6 +729,29 @@ char *alloc_sub_advanced(const char *servicename, const char *user,
        return ret_string;
 }
 
+/*
+ * This obviously is inefficient and needs to be merged into
+ * alloc_sub_advanced...
+ */
+
+char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
+                         const char *servicename, const char *user, 
+                         const char *connectpath, gid_t gid, 
+                         const char *smb_name, const char *domain_name,
+                         const char *str)
+{
+       char *a, *t;
+
+       if (!(a = alloc_sub_advanced(servicename, user, connectpath, gid,
+                                    smb_name, domain_name, str))) {
+               return NULL;
+       }
+       t = talloc_strdup(mem_ctx, a);
+       SAFE_FREE(a);
+       return t;
+}
+
+
 void standard_sub_advanced(const char *servicename, const char *user, 
                           const char *connectpath, gid_t gid, 
                           const char *smb_name, const char *domain_name,
@@ -746,3 +767,21 @@ void standard_sub_advanced(const char *servicename, const char *user,
                SAFE_FREE( s );
        }
 }
+
+/****************************************************************************
+ *  Do some standard substitutions in a string.
+ *  ****************************************************************************/
+
+void standard_sub_conn(connection_struct *conn, char *str, size_t len)
+{
+       char *s;
+
+       s = alloc_sub_advanced(lp_servicename(SNUM(conn)), conn->user, conn->connectpath,
+                              conn->gid, smb_user_name, "", str);
+
+       if ( s ) {
+               strncpy( str, s, len );
+               SAFE_FREE( s );
+       }
+}
+