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 realy 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)
47 alpha_strcpy(s, str, SAFE_NETBIOS_CHARS, strlen(s)+1);
49 trim_string(s," "," ");
56 void sub_set_remote_proto(const char *str)
59 setup_string(&sub->remote_proto, str);
62 void sub_set_remote_arch(const char *str)
65 setup_string(&sub->remote_arch, str);
69 setup the string used by %U substitution
71 void sub_set_user_name(const char *name)
74 setup_string(&sub->user_name, name);
77 /****************************************************************************
79 ****************************************************************************/
80 void standard_sub_basic(char *str,size_t len)
84 /****************************************************************************
85 Do some standard substitutions in a string.
86 This function will return an allocated string that have to be freed.
87 ****************************************************************************/
88 char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str)
90 return talloc_strdup(mem_ctx, str);
93 char *alloc_sub_basic(const char *smb_name, const char *str)
98 /****************************************************************************
99 Do some specific substitutions in a string.
100 This function will return an allocated string that have to be freed.
101 ****************************************************************************/
103 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
104 const char *input_string,
105 const char *username,
110 return talloc_strdup(mem_ctx, input_string);
113 char *alloc_sub_specified(const char *input_string,
114 const char *username,
119 return strdup(input_string);
122 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
125 const char *connectpath,
127 const char *smb_name,
130 return talloc_strdup(mem_ctx, str);
133 char *alloc_sub_advanced(int snum, const char *user,
134 const char *connectpath, gid_t gid,
135 const char *smb_name, char *str)
140 /****************************************************************************
141 Do some standard substitutions in a string.
142 ****************************************************************************/
144 void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len)
148 char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str)
150 return talloc_strdup(mem_ctx, str);
153 char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str)
158 /****************************************************************************
159 Like standard_sub but by snum.
160 ****************************************************************************/
162 void standard_sub_snum(int snum, char *str, size_t len)