2 Unix SMB/CIFS implementation.
4 common server info functions
6 Copyright (C) Stefan (metze) Metzmacher 2004
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.
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.
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/>.
23 #include "librpc/gen_ndr/srvsvc.h"
24 #include "rpc_server/dcerpc_server.h"
25 #include "dsdb/samdb/samdb.h"
26 #include "dsdb/common/util.h"
27 #include "auth/auth.h"
28 #include "param/param.h"
29 #include "rpc_server/common/common.h"
30 #include "libds/common/roles.h"
31 #include "auth/auth_util.h"
32 #include "lib/tsocket/tsocket.h"
35 Here are common server info functions used by some dcerpc server interfaces
38 /* This hardcoded value should go into a ldb database! */
39 enum srvsvc_PlatformId
dcesrv_common_get_platform_id(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
41 enum srvsvc_PlatformId id
;
43 id
= lpcfg_parm_int(dce_ctx
->lp_ctx
, NULL
, "server_info", "platform_id", PLATFORM_ID_NT
);
48 const char *dcesrv_common_get_server_name(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
, const char *server_unc
)
50 const char *p
= server_unc
;
52 /* if there's no string return our NETBIOS name */
54 return talloc_strdup(mem_ctx
, lpcfg_netbios_name(dce_ctx
->lp_ctx
));
57 /* if there're '\\\\' in front remove them otherwise just pass the string */
58 if (p
[0] == '\\' && p
[1] == '\\') {
62 return talloc_strdup(mem_ctx
, p
);
66 /* This hardcoded value should go into a ldb database! */
67 uint32_t dcesrv_common_get_server_type(TALLOC_CTX
*mem_ctx
, struct tevent_context
*event_ctx
, struct dcesrv_context
*dce_ctx
)
69 int default_server_announce
= 0;
70 default_server_announce
|= SV_TYPE_WORKSTATION
;
71 default_server_announce
|= SV_TYPE_SERVER
;
72 default_server_announce
|= SV_TYPE_SERVER_UNIX
;
74 default_server_announce
|= SV_TYPE_SERVER_NT
;
75 default_server_announce
|= SV_TYPE_NT
;
77 switch (lpcfg_server_role(dce_ctx
->lp_ctx
)) {
78 case ROLE_DOMAIN_MEMBER
:
79 default_server_announce
|= SV_TYPE_DOMAIN_MEMBER
;
81 case ROLE_ACTIVE_DIRECTORY_DC
:
83 struct ldb_context
*samctx
;
84 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
89 samctx
= samdb_connect(
93 anonymous_session(tmp_ctx
, dce_ctx
->lp_ctx
),
97 DEBUG(2,("Unable to open samdb in determining server announce flags\n"));
99 /* Determine if we are the pdc */
100 bool is_pdc
= samdb_is_pdc(samctx
);
102 default_server_announce
|= SV_TYPE_DOMAIN_CTRL
;
104 default_server_announce
|= SV_TYPE_DOMAIN_BAKCTRL
;
108 talloc_free(tmp_ctx
);
111 case ROLE_STANDALONE
:
115 if (lpcfg_time_server(dce_ctx
->lp_ctx
))
116 default_server_announce
|= SV_TYPE_TIME_SOURCE
;
118 if (lpcfg_host_msdfs(dce_ctx
->lp_ctx
))
119 default_server_announce
|= SV_TYPE_DFS_SERVER
;
124 /* TODO: announce us as print server when we are a print server */
125 bool is_print_server
= false;
126 if (is_print_server
) {
127 default_server_announce
|= SV_TYPE_PRINTQ_SERVER
;
131 return default_server_announce
;
134 /* This hardcoded value should go into a ldb database! */
135 const char *dcesrv_common_get_lan_root(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
137 return talloc_strdup(mem_ctx
, "");
140 /* This hardcoded value should go into a ldb database! */
141 uint32_t dcesrv_common_get_users(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
146 /* This hardcoded value should go into a ldb database! */
147 uint32_t dcesrv_common_get_disc(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
152 /* This hardcoded value should go into a ldb database! */
153 uint32_t dcesrv_common_get_hidden(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
158 /* This hardcoded value should go into a ldb database! */
159 uint32_t dcesrv_common_get_announce(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
164 /* This hardcoded value should go into a ldb database! */
165 uint32_t dcesrv_common_get_anndelta(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
170 /* This hardcoded value should go into a ldb database! */
171 uint32_t dcesrv_common_get_licenses(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
176 /* This hardcoded value should go into a ldb database! */
177 const char *dcesrv_common_get_userpath(TALLOC_CTX
*mem_ctx
, struct dcesrv_context
*dce_ctx
)
179 return talloc_strdup(mem_ctx
, "c:\\");
182 #define INVALID_SHARE_NAME_CHARS " \"*+,./:;<=>?[\\]|"
184 bool dcesrv_common_validate_share_name(TALLOC_CTX
*mem_ctx
, const char *share_name
)
186 if (strpbrk(share_name
, INVALID_SHARE_NAME_CHARS
)) {
194 * call_session_info is session info for samdb. call_audit_session_info is for
195 * auditing and may be NULL.
197 struct ldb_context
*dcesrv_samdb_connect_session_info(
199 struct dcesrv_call_state
*dce_call
,
200 const struct auth_session_info
*call_session_info
,
201 const struct auth_session_info
*call_audit_session_info
)
203 struct ldb_context
*samdb
= NULL
;
204 struct auth_session_info
*user_session_info
= NULL
;
205 struct auth_session_info
*audit_session_info
= NULL
;
206 struct tsocket_address
*remote_address
= NULL
;
208 user_session_info
= copy_session_info(mem_ctx
, call_session_info
);
209 if (user_session_info
== NULL
) {
213 if (call_audit_session_info
!= NULL
) {
214 audit_session_info
= copy_session_info(mem_ctx
, call_audit_session_info
);
215 if (audit_session_info
== NULL
) {
216 talloc_free(user_session_info
);
221 if (dce_call
->conn
->remote_address
!= NULL
) {
222 remote_address
= tsocket_address_copy(dce_call
->conn
->remote_address
,
224 if (remote_address
== NULL
) {
225 TALLOC_FREE(audit_session_info
);
226 talloc_free(user_session_info
);
232 * We need to make sure every argument
233 * stays around for the lifetime of 'samdb',
234 * typically it is allocated on the scope of
235 * an assoc group, so we can't reference dce_call->conn,
236 * as the assoc group may stay when the current connection
239 * The following are global per process:
240 * - dce_call->conn->dce_ctx->lp_ctx
241 * - dce_call->event_ctx
245 * - dce_call->conn->remote_address
246 * - dce_call->auth_state->session_info
248 samdb
= samdb_connect(
251 dce_call
->conn
->dce_ctx
->lp_ctx
,
256 TALLOC_FREE(audit_session_info
);
257 talloc_free(user_session_info
);
260 talloc_move(samdb
, &user_session_info
);
262 if (audit_session_info
!= NULL
) {
265 talloc_steal(samdb
, audit_session_info
);
267 ret
= ldb_set_opaque(samdb
,
268 DSDB_NETWORK_SESSION_INFO
,
270 if (ret
!= LDB_SUCCESS
) {
280 * Open an ldb connection under the system session and save the remote users
281 * session details in a ldb_opaque. This will allow the audit logging to
282 * log the original session for operations performed in the system session.
284 * Access checks are required by the caller!
286 struct ldb_context
*dcesrv_samdb_connect_as_system(
288 struct dcesrv_call_state
*dce_call
)
290 const struct auth_session_info
*system_session_info
= NULL
;
291 const struct auth_session_info
*call_session_info
= NULL
;
293 system_session_info
= system_session(dce_call
->conn
->dce_ctx
->lp_ctx
);
294 if (system_session_info
== NULL
) {
298 call_session_info
= dcesrv_call_session_info(dce_call
);
300 return dcesrv_samdb_connect_session_info(mem_ctx
, dce_call
,
301 system_session_info
, call_session_info
);
305 * Open an ldb connection under the remote users session details.
307 * Access checks are done at the ldb level.
309 struct ldb_context
*dcesrv_samdb_connect_as_user(
311 struct dcesrv_call_state
*dce_call
)
313 const struct auth_session_info
*call_session_info
= NULL
;
315 call_session_info
= dcesrv_call_session_info(dce_call
);
317 return dcesrv_samdb_connect_session_info(mem_ctx
, dce_call
,
318 call_session_info
, NULL
);