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