s4:lib/tevent: rename structs
[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
64 /* This hardcoded value should go into a ldb database! */
65 uint32_t dcesrv_common_get_server_type(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx, struct dcesrv_context *dce_ctx)
66 {
67         int default_server_announce = 0;
68         default_server_announce |= SV_TYPE_WORKSTATION;
69         default_server_announce |= SV_TYPE_SERVER;
70         default_server_announce |= SV_TYPE_SERVER_UNIX;
71
72         switch (lp_announce_as(dce_ctx->lp_ctx)) {
73                 case ANNOUNCE_AS_NT_SERVER:
74                         default_server_announce |= SV_TYPE_SERVER_NT;
75                         /* fall through... */
76                 case ANNOUNCE_AS_NT_WORKSTATION:
77                         default_server_announce |= SV_TYPE_NT;
78                         break;
79                 case ANNOUNCE_AS_WIN95:
80                         default_server_announce |= SV_TYPE_WIN95_PLUS;
81                         break;
82                 case ANNOUNCE_AS_WFW:
83                         default_server_announce |= SV_TYPE_WFW;
84                         break;
85                 default:
86                         break;
87         }
88
89         switch (lp_server_role(dce_ctx->lp_ctx)) {
90                 case ROLE_DOMAIN_MEMBER:
91                         default_server_announce |= SV_TYPE_DOMAIN_MEMBER;
92                         break;
93                 case ROLE_DOMAIN_CONTROLLER:
94                 {
95                         struct ldb_context *samctx;
96                         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
97                         if (!tmp_ctx) {
98                                 break;
99                         }
100                         /* open main ldb */
101                         samctx = samdb_connect(tmp_ctx, event_ctx, dce_ctx->lp_ctx, anonymous_session(tmp_ctx, event_ctx, dce_ctx->lp_ctx));
102                         if (samctx == NULL) {
103                                 DEBUG(2,("Unable to open samdb in determining server announce flags\n"));
104                         } else {
105                                 /* Determine if we are the pdc */
106                                 bool is_pdc = samdb_is_pdc(samctx);
107                                 if (is_pdc) {
108                                         default_server_announce |= SV_TYPE_DOMAIN_CTRL;
109                                 } else {
110                                         default_server_announce |= SV_TYPE_DOMAIN_BAKCTRL;
111                                 }
112                         }
113                         /* Close it */
114                         talloc_free(tmp_ctx);
115                         break;
116                 }
117                 case ROLE_STANDALONE:
118                 default:
119                         break;
120         }
121         if (lp_time_server(dce_ctx->lp_ctx))
122                 default_server_announce |= SV_TYPE_TIME_SOURCE;
123
124         if (lp_host_msdfs(dce_ctx->lp_ctx))
125                 default_server_announce |= SV_TYPE_DFS_SERVER;
126
127
128 #if 0
129         { 
130                 /* TODO: announce us as print server when we are a print server */
131                 bool is_print_server = false;
132                 if (is_print_server) {
133                         default_server_announce |= SV_TYPE_PRINTQ_SERVER;
134                 }
135         }
136 #endif
137         return default_server_announce;
138 }
139
140 /* This hardcoded value should go into a ldb database! */
141 const char *dcesrv_common_get_lan_root(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
142 {
143         return talloc_strdup(mem_ctx, "");
144 }
145
146 /* This hardcoded value should go into a ldb database! */
147 uint32_t dcesrv_common_get_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
148 {
149         return -1;
150 }
151
152 /* This hardcoded value should go into a ldb database! */
153 uint32_t dcesrv_common_get_disc(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
154 {
155         return 15;
156 }
157
158 /* This hardcoded value should go into a ldb database! */
159 uint32_t dcesrv_common_get_hidden(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
160 {
161         return 0;
162 }
163
164 /* This hardcoded value should go into a ldb database! */
165 uint32_t dcesrv_common_get_announce(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
166 {
167         return 240;
168 }
169
170 /* This hardcoded value should go into a ldb database! */
171 uint32_t dcesrv_common_get_anndelta(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
172 {
173         return 3000;
174 }
175
176 /* This hardcoded value should go into a ldb database! */
177 uint32_t dcesrv_common_get_licenses(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
178 {
179         return 0;
180 }
181
182 /* This hardcoded value should go into a ldb database! */
183 const char *dcesrv_common_get_userpath(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
184 {
185         return talloc_strdup(mem_ctx, "c:\\");
186 }
187
188 #define INVALID_SHARE_NAME_CHARS " \"*+,./:;<=>?[\\]|"
189
190 bool dcesrv_common_validate_share_name(TALLOC_CTX *mem_ctx, const char *share_name)
191 {
192         if (strpbrk(share_name, INVALID_SHARE_NAME_CHARS)) {
193                 return false;
194         }
195
196         return true;
197 }