ab04b3af1f7496cc5c474bb8d5a5b0a2ef5703e2
[kai/samba.git] / source4 / 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 #include "rpc_server/common/common.h"
30 #include "rpc_server/common/proto.h"
31
32 /* 
33     Here are common server info functions used by some dcerpc server interfaces
34 */
35
36 /* This hardcoded value should go into a ldb database! */
37 enum srvsvc_PlatformId dcesrv_common_get_platform_id(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
38 {
39         enum srvsvc_PlatformId id;
40
41         id = lp_parm_int(dce_ctx->lp_ctx, NULL, "server_info", "platform_id", PLATFORM_ID_NT);
42
43         return id;
44 }
45
46 const char *dcesrv_common_get_server_name(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, const char *server_unc)
47 {
48         const char *p = server_unc;
49
50         /* if there's no string return our NETBIOS name */
51         if (!p) {
52                 return talloc_strdup(mem_ctx, lp_netbios_name(dce_ctx->lp_ctx));
53         }
54
55         /* if there're '\\\\' in front remove them otherwise just pass the string */
56         if (p[0] == '\\' && p[1] == '\\') {
57                 p += 2;
58         }
59
60         return talloc_strdup(mem_ctx, p);
61 }
62
63 const char *dcesrv_common_get_domain_name(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
64 {
65         return talloc_strdup(mem_ctx, lp_workgroup(dce_ctx->lp_ctx));
66 }
67
68 /* This hardcoded value should go into a ldb database! */
69 uint32_t dcesrv_common_get_version_major(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
70 {
71         return lp_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
72 }
73
74 /* This hardcoded value should go into a ldb database! */
75 uint32_t dcesrv_common_get_version_minor(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
76 {
77         return lp_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
78 }
79
80 /* This hardcoded value should go into a ldb database! */
81 uint32_t dcesrv_common_get_version_build(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
82 {
83         return lp_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
84 }
85
86 /* This hardcoded value should go into a ldb database! */
87 uint32_t dcesrv_common_get_server_type(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, struct dcesrv_context *dce_ctx)
88 {
89         int default_server_announce = 0;
90         default_server_announce |= SV_TYPE_WORKSTATION;
91         default_server_announce |= SV_TYPE_SERVER;
92         default_server_announce |= SV_TYPE_SERVER_UNIX;
93
94         switch (lp_announce_as(dce_ctx->lp_ctx)) {
95                 case ANNOUNCE_AS_NT_SERVER:
96                         default_server_announce |= SV_TYPE_SERVER_NT;
97                         /* fall through... */
98                 case ANNOUNCE_AS_NT_WORKSTATION:
99                         default_server_announce |= SV_TYPE_NT;
100                         break;
101                 case ANNOUNCE_AS_WIN95:
102                         default_server_announce |= SV_TYPE_WIN95_PLUS;
103                         break;
104                 case ANNOUNCE_AS_WFW:
105                         default_server_announce |= SV_TYPE_WFW;
106                         break;
107                 default:
108                         break;
109         }
110
111         switch (lp_server_role(dce_ctx->lp_ctx)) {
112                 case ROLE_DOMAIN_MEMBER:
113                         default_server_announce |= SV_TYPE_DOMAIN_MEMBER;
114                         break;
115                 case ROLE_DOMAIN_CONTROLLER:
116                 {
117                         struct ldb_context *samctx;
118                         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
119                         if (!tmp_ctx) {
120                                 break;
121                         }
122                         /* open main ldb */
123                         samctx = samdb_connect(tmp_ctx, event_ctx, dce_ctx->lp_ctx, anonymous_session(tmp_ctx, event_ctx, dce_ctx->lp_ctx));
124                         if (samctx == NULL) {
125                                 DEBUG(2,("Unable to open samdb in determining server announce flags\n"));
126                         } else {
127                                 /* Determine if we are the pdc */
128                                 bool is_pdc = samdb_is_pdc(samctx);
129                                 if (is_pdc) {
130                                         default_server_announce |= SV_TYPE_DOMAIN_CTRL;
131                                 } else {
132                                         default_server_announce |= SV_TYPE_DOMAIN_BAKCTRL;
133                                 }
134                         }
135                         /* Close it */
136                         talloc_free(tmp_ctx);
137                         break;
138                 }
139                 case ROLE_STANDALONE:
140                 default:
141                         break;
142         }
143         if (lp_time_server(dce_ctx->lp_ctx))
144                 default_server_announce |= SV_TYPE_TIME_SOURCE;
145
146         if (lp_host_msdfs(dce_ctx->lp_ctx))
147                 default_server_announce |= SV_TYPE_DFS_SERVER;
148
149
150 #if 0
151         { 
152                 /* TODO: announce us as print server when we are a print server */
153                 bool is_print_server = false;
154                 if (is_print_server) {
155                         default_server_announce |= SV_TYPE_PRINTQ_SERVER;
156                 }
157         }
158 #endif
159         return default_server_announce;
160 }
161
162 /* This hardcoded value should go into a ldb database! */
163 const char *dcesrv_common_get_lan_root(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
164 {
165         return talloc_strdup(mem_ctx, "");
166 }
167
168 /* This hardcoded value should go into a ldb database! */
169 uint32_t dcesrv_common_get_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
170 {
171         return -1;
172 }
173
174 /* This hardcoded value should go into a ldb database! */
175 uint32_t dcesrv_common_get_disc(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
176 {
177         return 15;
178 }
179
180 /* This hardcoded value should go into a ldb database! */
181 uint32_t dcesrv_common_get_hidden(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
182 {
183         return 0;
184 }
185
186 /* This hardcoded value should go into a ldb database! */
187 uint32_t dcesrv_common_get_announce(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
188 {
189         return 240;
190 }
191
192 /* This hardcoded value should go into a ldb database! */
193 uint32_t dcesrv_common_get_anndelta(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
194 {
195         return 3000;
196 }
197
198 /* This hardcoded value should go into a ldb database! */
199 uint32_t dcesrv_common_get_licenses(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
200 {
201         return 0;
202 }
203
204 /* This hardcoded value should go into a ldb database! */
205 const char *dcesrv_common_get_userpath(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
206 {
207         return talloc_strdup(mem_ctx, "c:\\");
208 }
209
210 #define INVALID_SHARE_NAME_CHARS " \"*+,./:;<=>?[\\]|"
211
212 bool dcesrv_common_validate_share_name(TALLOC_CTX *mem_ctx, const char *share_name)
213 {
214         if (strpbrk(share_name, INVALID_SHARE_NAME_CHARS)) {
215                 return false;
216         }
217
218         return true;
219 }