r13655: Use new name of build header
[jelmer/samba4-debian.git] / source / lib / util / substitute.c
1 /* 
2    Unix SMB/CIFS implementation.
3    string substitution functions
4    Copyright (C) Andrew Tridgell 1992-2000
5    
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.
10    
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.
15    
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.
19 */
20
21
22 #include "includes.h"
23 #include "smb_server/smb_server.h"
24
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;
29
30 void sub_set_context(struct substitute_context *subptr)
31 {
32         sub = subptr;
33 }
34
35 /*
36   setup a string in the negotiate structure, using alpha_strcpy with SAFE_NETBIOS_CHARS
37 */
38 static void setup_string(char **dest, const char *str)
39 {
40 #define SAFE_NETBIOS_CHARS ". -_"
41         char *s;
42
43         s = strdup(str);
44         if (!s) {
45                 return;
46         }
47
48         alpha_strcpy(s, str, SAFE_NETBIOS_CHARS, strlen(s)+1);
49
50         trim_string(s," "," ");
51         strlower(s);
52
53         SAFE_FREE(*dest);
54         (*dest) = s;
55 }
56
57 void sub_set_remote_proto(const char *str)
58 {
59         if (!sub) return;
60         setup_string(&sub->remote_proto, str);
61 }
62
63 void sub_set_remote_arch(const char *str)
64 {
65         if (!sub) return;
66         setup_string(&sub->remote_arch, str);
67 }
68
69 /*
70   setup the string used by %U substitution 
71 */
72 void sub_set_user_name(const char *name)
73 {
74         if (!sub) return;
75         setup_string(&sub->user_name, name);
76 }
77
78 /****************************************************************************
79 FOO
80 ****************************************************************************/
81 void standard_sub_basic(char *str,size_t len)
82 {
83 }
84
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)
90 {
91         return talloc_strdup(mem_ctx, str);
92 }
93
94 char *alloc_sub_basic(const char *smb_name, const char *str)
95 {
96         return strdup(str);
97 }
98
99 /****************************************************************************
100  Do some specific substitutions in a string.
101  This function will return an allocated string that have to be freed.
102 ****************************************************************************/
103
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)
110 {
111         return talloc_strdup(mem_ctx, input_string);
112 }
113
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)
119 {
120         return strdup(input_string);
121 }
122
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)
130 {
131         return talloc_strdup(mem_ctx, str);
132 }
133
134 char *alloc_sub_advanced(int snum, const char *user, 
135                                   const char *connectpath, gid_t gid, 
136                                   const char *smb_name, char *str)
137 {
138         return strdup(str);
139 }
140
141 /****************************************************************************
142  Do some standard substitutions in a string.
143 ****************************************************************************/
144
145 void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len)
146 {
147 }
148
149 char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str)
150 {
151         return talloc_strdup(mem_ctx, str);
152 }
153
154 char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str)
155 {
156         return strdup(str);
157 }
158
159 /****************************************************************************
160  Like standard_sub but by snum.
161 ****************************************************************************/
162
163 void standard_sub_snum(int snum, char *str, size_t len)
164 {
165 }