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 "auth/auth.h"
27 #include "param/param.h"
28 #include "rpc_server/common/common.h"
29 #include "libds/common/roles.h"
32 Here are common server info functions used by some dcerpc server interfaces
35 /* This hardcoded value should go into a ldb database! */
36 enum srvsvc_PlatformId dcesrv_common_get_platform_id(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
38 enum srvsvc_PlatformId id;
40 id = lpcfg_parm_int(dce_ctx->lp_ctx, NULL, "server_info", "platform_id", PLATFORM_ID_NT);
45 const char *dcesrv_common_get_server_name(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, const char *server_unc)
47 const char *p = server_unc;
49 /* if there's no string return our NETBIOS name */
51 return talloc_strdup(mem_ctx, lpcfg_netbios_name(dce_ctx->lp_ctx));
54 /* if there're '\\\\' in front remove them otherwise just pass the string */
55 if (p[0] == '\\' && p[1] == '\\') {
59 return talloc_strdup(mem_ctx, p);
63 /* This hardcoded value should go into a ldb database! */
64 uint32_t dcesrv_common_get_server_type(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx, struct dcesrv_context *dce_ctx)
66 int default_server_announce = 0;
67 default_server_announce |= SV_TYPE_WORKSTATION;
68 default_server_announce |= SV_TYPE_SERVER;
69 default_server_announce |= SV_TYPE_SERVER_UNIX;
71 default_server_announce |= SV_TYPE_SERVER_NT;
72 default_server_announce |= SV_TYPE_NT;
74 switch (lpcfg_server_role(dce_ctx->lp_ctx)) {
75 case ROLE_DOMAIN_MEMBER:
76 default_server_announce |= SV_TYPE_DOMAIN_MEMBER;
78 case ROLE_ACTIVE_DIRECTORY_DC:
80 struct ldb_context *samctx;
81 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
86 samctx = samdb_connect(
90 anonymous_session(tmp_ctx, dce_ctx->lp_ctx),
94 DEBUG(2,("Unable to open samdb in determining server announce flags\n"));
96 /* Determine if we are the pdc */
97 bool is_pdc = samdb_is_pdc(samctx);
99 default_server_announce |= SV_TYPE_DOMAIN_CTRL;
101 default_server_announce |= SV_TYPE_DOMAIN_BAKCTRL;
105 talloc_free(tmp_ctx);
108 case ROLE_STANDALONE:
112 if (lpcfg_time_server(dce_ctx->lp_ctx))
113 default_server_announce |= SV_TYPE_TIME_SOURCE;
115 if (lpcfg_host_msdfs(dce_ctx->lp_ctx))
116 default_server_announce |= SV_TYPE_DFS_SERVER;
121 /* TODO: announce us as print server when we are a print server */
122 bool is_print_server = false;
123 if (is_print_server) {
124 default_server_announce |= SV_TYPE_PRINTQ_SERVER;
128 return default_server_announce;
131 /* This hardcoded value should go into a ldb database! */
132 const char *dcesrv_common_get_lan_root(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
134 return talloc_strdup(mem_ctx, "");
137 /* This hardcoded value should go into a ldb database! */
138 uint32_t dcesrv_common_get_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
143 /* This hardcoded value should go into a ldb database! */
144 uint32_t dcesrv_common_get_disc(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
149 /* This hardcoded value should go into a ldb database! */
150 uint32_t dcesrv_common_get_hidden(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
155 /* This hardcoded value should go into a ldb database! */
156 uint32_t dcesrv_common_get_announce(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
161 /* This hardcoded value should go into a ldb database! */
162 uint32_t dcesrv_common_get_anndelta(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
167 /* This hardcoded value should go into a ldb database! */
168 uint32_t dcesrv_common_get_licenses(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
173 /* This hardcoded value should go into a ldb database! */
174 const char *dcesrv_common_get_userpath(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
176 return talloc_strdup(mem_ctx, "c:\\");
179 #define INVALID_SHARE_NAME_CHARS " \"*+,./:;<=>?[\\]|"
181 bool dcesrv_common_validate_share_name(TALLOC_CTX *mem_ctx, const char *share_name)
183 if (strpbrk(share_name, INVALID_SHARE_NAME_CHARS)) {
191 * Open an ldb connection under the system session and save the remote users
192 * session details in a ldb_opaque. This will allow the audit logging to
193 * log the original session for operations performed in the system session.
195 struct ldb_context *dcesrv_samdb_connect_as_system(
197 struct dcesrv_call_state *dce_call)
199 struct ldb_context *samdb = NULL;
200 samdb = samdb_connect(
203 dce_call->conn->dce_ctx->lp_ctx,
204 system_session(dce_call->conn->dce_ctx->lp_ctx),
205 dce_call->conn->remote_address,
210 "networkSessionInfo",
211 dce_call->conn->auth_state.session_info);