Merge commit 'release-4-0-0alpha1' into v4-0-test
[ira/wip.git] / source / rpc_server / common / server_info.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    common server info functions
5
6    Copyright (C) Stefan (metze) Metzmacher 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_srvsvc.h"
24 #include "librpc/gen_ndr/svcctl.h"
25 #include "rpc_server/dcerpc_server.h"
26 #include "dsdb/samdb/samdb.h"
27 #include "auth/auth.h"
28 #include "param/param.h"
29
30 /* 
31     Here are common server info functions used by some dcerpc server interfaces
32 */
33
34 /* This hardcoded value should go into a ldb database! */
35 _PUBLIC_ enum srvsvc_PlatformId dcesrv_common_get_platform_id(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
36 {
37         enum srvsvc_PlatformId id;
38
39         id = lp_parm_int(global_loadparm, NULL, "server_info", "platform_id", PLATFORM_ID_NT);
40
41         return id;
42 }
43
44 _PUBLIC_ const char *dcesrv_common_get_server_name(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, const char *server_unc)
45 {
46         const char *p = server_unc;
47
48         /* if there's no string return our NETBIOS name */
49         if (!p) {
50                 return talloc_strdup(mem_ctx, lp_netbios_name(global_loadparm));
51         }
52
53         /* if there're '\\\\' in front remove them otherwise just pass the string */
54         if (p[0] == '\\' && p[1] == '\\') {
55                 p += 2;
56         }
57
58         return talloc_strdup(mem_ctx, p);
59 }
60
61 const char *dcesrv_common_get_domain_name(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
62 {
63         return talloc_strdup(mem_ctx, lp_workgroup(global_loadparm));
64 }
65
66 /* This hardcoded value should go into a ldb database! */
67 _PUBLIC_ uint32_t dcesrv_common_get_version_major(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
68 {
69         return lp_parm_int(global_loadparm, NULL, "server_info", "version_major", 5);
70 }
71
72 /* This hardcoded value should go into a ldb database! */
73 _PUBLIC_ uint32_t dcesrv_common_get_version_minor(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
74 {
75         return lp_parm_int(global_loadparm, NULL, "server_info", "version_minor", 2);
76 }
77
78 /* This hardcoded value should go into a ldb database! */
79 _PUBLIC_ uint32_t dcesrv_common_get_version_build(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
80 {
81         return lp_parm_int(global_loadparm, NULL, "server_info", "version_build", 3790);
82 }
83
84 /* This hardcoded value should go into a ldb database! */
85 _PUBLIC_ uint32_t dcesrv_common_get_server_type(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
86 {
87         int default_server_announce = 0;
88         default_server_announce |= SV_TYPE_WORKSTATION;
89         default_server_announce |= SV_TYPE_SERVER;
90         default_server_announce |= SV_TYPE_SERVER_UNIX;
91
92         switch (lp_announce_as(global_loadparm)) {
93                 case ANNOUNCE_AS_NT_SERVER:
94                         default_server_announce |= SV_TYPE_SERVER_NT;
95                         /* fall through... */
96                 case ANNOUNCE_AS_NT_WORKSTATION:
97                         default_server_announce |= SV_TYPE_NT;
98                         break;
99                 case ANNOUNCE_AS_WIN95:
100                         default_server_announce |= SV_TYPE_WIN95_PLUS;
101                         break;
102                 case ANNOUNCE_AS_WFW:
103                         default_server_announce |= SV_TYPE_WFW;
104                         break;
105                 default:
106                         break;
107         }
108
109         switch (lp_server_role(global_loadparm)) {
110                 case ROLE_DOMAIN_MEMBER:
111                         default_server_announce |= SV_TYPE_DOMAIN_MEMBER;
112                         break;
113                 case ROLE_DOMAIN_CONTROLLER:
114                 {
115                         struct ldb_context *samctx;
116                         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
117                         if (!tmp_ctx) {
118                                 break;
119                         }
120                         /* open main ldb */
121                         samctx = samdb_connect(tmp_ctx, anonymous_session(tmp_ctx));
122                         if (samctx == NULL) {
123                                 DEBUG(2,("Unable to open samdb in determining server announce flags\n"));
124                         } else {
125                                 /* Determine if we are the pdc */
126                                 bool is_pdc = samdb_is_pdc(samctx);
127                                 if (is_pdc) {
128                                         default_server_announce |= SV_TYPE_DOMAIN_CTRL;
129                                 } else {
130                                         default_server_announce |= SV_TYPE_DOMAIN_BAKCTRL;
131                                 }
132                         }
133                         /* Close it */
134                         talloc_free(tmp_ctx);
135                         break;
136                 }
137                 case ROLE_STANDALONE:
138                 default:
139                         break;
140         }
141         if (lp_time_server(global_loadparm))
142                 default_server_announce |= SV_TYPE_TIME_SOURCE;
143
144         if (lp_host_msdfs(global_loadparm))
145                 default_server_announce |= SV_TYPE_DFS_SERVER;
146
147
148 #if 0
149         { 
150                 /* TODO: announce us as print server when we are a print server */
151                 bool is_print_server = false;
152                 if (is_print_server) {
153                         default_server_announce |= SV_TYPE_PRINTQ_SERVER;
154                 }
155         }
156 #endif
157         return default_server_announce;
158 }
159
160 /* This hardcoded value should go into a ldb database! */
161 _PUBLIC_ const char *dcesrv_common_get_lan_root(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
162 {
163         return talloc_strdup(mem_ctx, "");
164 }
165
166 /* This hardcoded value should go into a ldb database! */
167 _PUBLIC_ uint32_t dcesrv_common_get_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
168 {
169         return -1;
170 }
171
172 /* This hardcoded value should go into a ldb database! */
173 _PUBLIC_ uint32_t dcesrv_common_get_disc(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
174 {
175         return 15;
176 }
177
178 /* This hardcoded value should go into a ldb database! */
179 _PUBLIC_ uint32_t dcesrv_common_get_hidden(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
180 {
181         return 0;
182 }
183
184 /* This hardcoded value should go into a ldb database! */
185 _PUBLIC_ uint32_t dcesrv_common_get_announce(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
186 {
187         return 240;
188 }
189
190 /* This hardcoded value should go into a ldb database! */
191 _PUBLIC_ uint32_t dcesrv_common_get_anndelta(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
192 {
193         return 3000;
194 }
195
196 /* This hardcoded value should go into a ldb database! */
197 _PUBLIC_ uint32_t dcesrv_common_get_licenses(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
198 {
199         return 0;
200 }
201
202 /* This hardcoded value should go into a ldb database! */
203 _PUBLIC_ const char *dcesrv_common_get_userpath(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
204 {
205         return talloc_strdup(mem_ctx, "c:\\");
206 }
207
208 #define INVALID_SHARE_NAME_CHARS " \"*+,./:;<=>?[\\]|"
209
210 _PUBLIC_ bool dcesrv_common_validate_share_name(TALLOC_CTX *mem_ctx, const char *share_name)
211 {
212         if (strpbrk(share_name, INVALID_SHARE_NAME_CHARS)) {
213                 return false;
214         }
215
216         return true;
217 }