r8974: Support makefile fragments in .mk files
[Samba/gbeck.git] / source4 / lib / substitute.c
bloba351db1af21aa2b17ca502ea5cedc6e59ac98b17
1 /*
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.
22 #include "includes.h"
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)
32 sub = 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 ". -_"
41 char *s;
43 s = strdup(str);
44 if (!s) {
45 return;
48 alpha_strcpy(s, str, SAFE_NETBIOS_CHARS, strlen(s)+1);
50 trim_string(s," "," ");
51 strlower(s);
53 SAFE_FREE(*dest);
54 (*dest) = s;
57 void sub_set_remote_proto(const char *str)
59 if (!sub) return;
60 setup_string(&sub->remote_proto, str);
63 void sub_set_remote_arch(const char *str)
65 if (!sub) return;
66 setup_string(&sub->remote_arch, str);
70 setup the string used by %U substitution
72 void sub_set_user_name(const char *name)
74 if (!sub) return;
75 setup_string(&sub->user_name, name);
78 /****************************************************************************
79 FOO
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)
96 return strdup(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,
107 const char *domain,
108 uid_t uid,
109 gid_t gid)
111 return talloc_strdup(mem_ctx, input_string);
114 char *alloc_sub_specified(const char *input_string,
115 const char *username,
116 const char *domain,
117 uid_t uid,
118 gid_t gid)
120 return strdup(input_string);
123 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
124 int snum,
125 const char *user,
126 const char *connectpath,
127 gid_t gid,
128 const char *smb_name,
129 char *str)
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)
138 return strdup(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)
156 return strdup(str);
159 /****************************************************************************
160 Like standard_sub but by snum.
161 ****************************************************************************/
163 void standard_sub_snum(int snum, char *str, size_t len)