r3466: split out request.h, signing.h, and smb_server.h
[metze/samba/wip.git] / source4 / lib / 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 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;
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         char *s;
41
42         s = strdup(str);
43         if (!s) {
44                 return;
45         }
46
47         alpha_strcpy(s, str, SAFE_NETBIOS_CHARS, strlen(s)+1);
48
49         trim_string(s," "," ");
50         strlower(s);
51
52         SAFE_FREE(*dest);
53         (*dest) = s;
54 }
55
56 void sub_set_remote_proto(const char *str)
57 {
58         if (!sub) return;
59         setup_string(&sub->remote_proto, str);
60 }
61
62 void sub_set_remote_arch(const char *str)
63 {
64         if (!sub) return;
65         setup_string(&sub->remote_arch, str);
66 }
67
68 /*
69   setup the string used by %U substitution 
70 */
71 void sub_set_user_name(const char *name)
72 {
73         if (!sub) return;
74         setup_string(&sub->user_name, name);
75 }
76
77 /****************************************************************************
78 FOO
79 ****************************************************************************/
80 void standard_sub_basic(char *str,size_t len)
81 {
82 }
83
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)
89 {
90         return talloc_strdup(mem_ctx, str);
91 }
92
93 char *alloc_sub_basic(const char *smb_name, const char *str)
94 {
95         return strdup(str);
96 }
97
98 /****************************************************************************
99  Do some specific substitutions in a string.
100  This function will return an allocated string that have to be freed.
101 ****************************************************************************/
102
103 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
104                         const char *input_string,
105                         const char *username,
106                         const char *domain,
107                         uid_t uid,
108                         gid_t gid)
109 {
110         return talloc_strdup(mem_ctx, input_string);
111 }
112
113 char *alloc_sub_specified(const char *input_string,
114                         const char *username,
115                         const char *domain,
116                         uid_t uid,
117                         gid_t gid)
118 {
119         return strdup(input_string);
120 }
121
122 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
123                         int snum,
124                         const char *user,
125                         const char *connectpath,
126                         gid_t gid,
127                         const char *smb_name,
128                         char *str)
129 {
130         return talloc_strdup(mem_ctx, str);
131 }
132
133 char *alloc_sub_advanced(int snum, const char *user, 
134                                   const char *connectpath, gid_t gid, 
135                                   const char *smb_name, char *str)
136 {
137         return strdup(str);
138 }
139
140 /****************************************************************************
141  Do some standard substitutions in a string.
142 ****************************************************************************/
143
144 void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len)
145 {
146 }
147
148 char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str)
149 {
150         return talloc_strdup(mem_ctx, str);
151 }
152
153 char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str)
154 {
155         return strdup(str);
156 }
157
158 /****************************************************************************
159  Like standard_sub but by snum.
160 ****************************************************************************/
161
162 void standard_sub_snum(int snum, char *str, size_t len)
163 {
164 }