s3: Optimize g_lock_lock for a heavily contended case
[Samba.git] / source4 / rpc_server / common / server_info.c
blob66264feb46071ce3fbb379091bb2956087ee329d
1 /*
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/>.
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 #include "rpc_server/common/common.h"
30 /*
31 Here are common server info functions used by some dcerpc server interfaces
34 /* This hardcoded value should go into a ldb database! */
35 enum srvsvc_PlatformId dcesrv_common_get_platform_id(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
37 enum srvsvc_PlatformId id;
39 id = lp_parm_int(dce_ctx->lp_ctx, NULL, "server_info", "platform_id", PLATFORM_ID_NT);
41 return id;
44 const char *dcesrv_common_get_server_name(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, const char *server_unc)
46 const char *p = server_unc;
48 /* if there's no string return our NETBIOS name */
49 if (!p) {
50 return talloc_strdup(mem_ctx, lp_netbios_name(dce_ctx->lp_ctx));
53 /* if there're '\\\\' in front remove them otherwise just pass the string */
54 if (p[0] == '\\' && p[1] == '\\') {
55 p += 2;
58 return talloc_strdup(mem_ctx, p);
62 /* This hardcoded value should go into a ldb database! */
63 uint32_t dcesrv_common_get_server_type(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx, struct dcesrv_context *dce_ctx)
65 int default_server_announce = 0;
66 default_server_announce |= SV_TYPE_WORKSTATION;
67 default_server_announce |= SV_TYPE_SERVER;
68 default_server_announce |= SV_TYPE_SERVER_UNIX;
70 switch (lp_announce_as(dce_ctx->lp_ctx)) {
71 case ANNOUNCE_AS_NT_SERVER:
72 default_server_announce |= SV_TYPE_SERVER_NT;
73 /* fall through... */
74 case ANNOUNCE_AS_NT_WORKSTATION:
75 default_server_announce |= SV_TYPE_NT;
76 break;
77 case ANNOUNCE_AS_WIN95:
78 default_server_announce |= SV_TYPE_WIN95_PLUS;
79 break;
80 case ANNOUNCE_AS_WFW:
81 default_server_announce |= SV_TYPE_WFW;
82 break;
83 default:
84 break;
87 switch (lp_server_role(dce_ctx->lp_ctx)) {
88 case ROLE_DOMAIN_MEMBER:
89 default_server_announce |= SV_TYPE_DOMAIN_MEMBER;
90 break;
91 case ROLE_DOMAIN_CONTROLLER:
93 struct ldb_context *samctx;
94 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
95 if (!tmp_ctx) {
96 break;
98 /* open main ldb */
99 samctx = samdb_connect(tmp_ctx, event_ctx, dce_ctx->lp_ctx, anonymous_session(tmp_ctx, event_ctx, dce_ctx->lp_ctx));
100 if (samctx == NULL) {
101 DEBUG(2,("Unable to open samdb in determining server announce flags\n"));
102 } else {
103 /* Determine if we are the pdc */
104 bool is_pdc = samdb_is_pdc(samctx);
105 if (is_pdc) {
106 default_server_announce |= SV_TYPE_DOMAIN_CTRL;
107 } else {
108 default_server_announce |= SV_TYPE_DOMAIN_BAKCTRL;
111 /* Close it */
112 talloc_free(tmp_ctx);
113 break;
115 case ROLE_STANDALONE:
116 default:
117 break;
119 if (lp_time_server(dce_ctx->lp_ctx))
120 default_server_announce |= SV_TYPE_TIME_SOURCE;
122 if (lp_host_msdfs(dce_ctx->lp_ctx))
123 default_server_announce |= SV_TYPE_DFS_SERVER;
126 #if 0
128 /* TODO: announce us as print server when we are a print server */
129 bool is_print_server = false;
130 if (is_print_server) {
131 default_server_announce |= SV_TYPE_PRINTQ_SERVER;
134 #endif
135 return default_server_announce;
138 /* This hardcoded value should go into a ldb database! */
139 const char *dcesrv_common_get_lan_root(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
141 return talloc_strdup(mem_ctx, "");
144 /* This hardcoded value should go into a ldb database! */
145 uint32_t dcesrv_common_get_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
147 return -1;
150 /* This hardcoded value should go into a ldb database! */
151 uint32_t dcesrv_common_get_disc(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
153 return 15;
156 /* This hardcoded value should go into a ldb database! */
157 uint32_t dcesrv_common_get_hidden(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
159 return 0;
162 /* This hardcoded value should go into a ldb database! */
163 uint32_t dcesrv_common_get_announce(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
165 return 240;
168 /* This hardcoded value should go into a ldb database! */
169 uint32_t dcesrv_common_get_anndelta(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
171 return 3000;
174 /* This hardcoded value should go into a ldb database! */
175 uint32_t dcesrv_common_get_licenses(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
177 return 0;
180 /* This hardcoded value should go into a ldb database! */
181 const char *dcesrv_common_get_userpath(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx)
183 return talloc_strdup(mem_ctx, "c:\\");
186 #define INVALID_SHARE_NAME_CHARS " \"*+,./:;<=>?[\\]|"
188 bool dcesrv_common_validate_share_name(TALLOC_CTX *mem_ctx, const char *share_name)
190 if (strpbrk(share_name, INVALID_SHARE_NAME_CHARS)) {
191 return false;
194 return true;