2 Unix SMB/CIFS implementation.
3 string substitution functions
4 Copyright (C) Andrew Tridgell 1992-2000
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "smb_server/smb_server.h"
25 /* oh bugger - I really didn't want to have a top-level context
26 anywhere, but until we change all lp_*() calls to take a context
27 argument this is needed */
28 static struct substitute_context *sub;
30 void sub_set_context(struct substitute_context *subptr)
36 setup a string in the negotiate structure, using alpha_strcpy with SAFE_NETBIOS_CHARS
38 static void setup_string(char **dest, const char *str)
40 #define SAFE_NETBIOS_CHARS ". -_"
48 alpha_strcpy(s, str, SAFE_NETBIOS_CHARS, strlen(s)+1);
50 trim_string(s," "," ");
57 void sub_set_remote_proto(const char *str)
60 setup_string(&sub->remote_proto, str);
63 void sub_set_remote_arch(const char *str)
66 setup_string(&sub->remote_arch, str);
70 setup the string used by %U substitution
72 void sub_set_user_name(const char *name)
75 setup_string(&sub->user_name, name);
78 /****************************************************************************
80 ****************************************************************************/
81 void standard_sub_basic(char *str,size_t len)
85 /****************************************************************************
86 Do some standard substitutions in a string.
87 This function will return an allocated string that have to be freed.
88 ****************************************************************************/
89 char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str)
91 return talloc_strdup(mem_ctx, str);
94 char *alloc_sub_basic(const char *smb_name, const char *str)
99 /****************************************************************************
100 Do some specific substitutions in a string.
101 This function will return an allocated string that have to be freed.
102 ****************************************************************************/
104 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
105 const char *input_string,
106 const char *username,
111 return talloc_strdup(mem_ctx, input_string);
114 char *alloc_sub_specified(const char *input_string,
115 const char *username,
120 return strdup(input_string);
123 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
126 const char *connectpath,
128 const char *smb_name,
131 return talloc_strdup(mem_ctx, str);
134 char *alloc_sub_advanced(int snum, const char *user,
135 const char *connectpath, gid_t gid,
136 const char *smb_name, char *str)
141 /****************************************************************************
142 Do some standard substitutions in a string.
143 ****************************************************************************/
145 void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len)
149 char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str)
151 return talloc_strdup(mem_ctx, str);
154 char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str)
159 /****************************************************************************
160 Like standard_sub but by snum.
161 ****************************************************************************/
163 void standard_sub_snum(int snum, char *str, size_t len)