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