r4348: syncing up for 3.0.11pre1
[Samba.git] / source / rpc_server / srv_srvsvc_nt.c
blobaf4c94800a5e3d711ade294ac3aab42fdd895814
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Jeremy Allison 2001.
6 * Copyright (C) Nigel Williams 2001.
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 2 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, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* This is the implementation of the srvsvc pipe. */
25 #include "includes.h"
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_SRV
30 /*******************************************************************
31 Utility function to get the 'type' of a share from an snum.
32 ********************************************************************/
33 static uint32 get_share_type(int snum)
35 char *net_name = lp_servicename(snum);
36 int len_net_name = strlen(net_name);
38 /* work out the share type */
39 uint32 type = STYPE_DISKTREE;
41 if (lp_print_ok(snum))
42 type = STYPE_PRINTQ;
43 if (strequal(lp_fstype(snum), "IPC"))
44 type = STYPE_IPC;
45 if (net_name[len_net_name] == '$')
46 type |= STYPE_HIDDEN;
48 return type;
51 /*******************************************************************
52 Fill in a share info level 0 structure.
53 ********************************************************************/
55 static void init_srv_share_info_0(pipes_struct *p, SRV_SHARE_INFO_0 *sh0, int snum)
57 pstring net_name;
59 pstrcpy(net_name, lp_servicename(snum));
61 init_srv_share_info0(&sh0->info_0, net_name);
62 init_srv_share_info0_str(&sh0->info_0_str, net_name);
65 /*******************************************************************
66 Fill in a share info level 1 structure.
67 ********************************************************************/
69 static void init_srv_share_info_1(pipes_struct *p, SRV_SHARE_INFO_1 *sh1, int snum)
71 pstring remark;
73 char *net_name = lp_servicename(snum);
74 pstrcpy(remark, lp_comment(snum));
75 standard_sub_conn(p->conn, remark,sizeof(remark));
77 init_srv_share_info1(&sh1->info_1, net_name, get_share_type(snum), remark);
78 init_srv_share_info1_str(&sh1->info_1_str, net_name, remark);
81 /*******************************************************************
82 Fill in a share info level 2 structure.
83 ********************************************************************/
85 static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2, int snum)
87 pstring remark;
88 pstring path;
89 pstring passwd;
91 char *net_name = lp_servicename(snum);
92 pstrcpy(remark, lp_comment(snum));
93 standard_sub_conn(p->conn, remark,sizeof(remark));
94 pstrcpy(path, "C:");
95 pstrcat(path, lp_pathname(snum));
98 * Change / to \\ so that win2k will see it as a valid path. This was added to
99 * enable use of browsing in win2k add share dialog.
102 string_replace(path, '/', '\\');
104 pstrcpy(passwd, "");
106 init_srv_share_info2(&sh2->info_2, net_name, get_share_type(snum), remark, 0, 0xffffffff, 1, path, passwd);
107 init_srv_share_info2_str(&sh2->info_2_str, net_name, remark, path, passwd);
110 /*******************************************************************
111 What to do when smb.conf is updated.
112 ********************************************************************/
114 static void smb_conf_updated(int msg_type, pid_t src, void *buf, size_t len)
116 DEBUG(10,("smb_conf_updated: Got message saying smb.conf was updated. Reloading.\n"));
117 reload_services(False);
120 /*******************************************************************
121 Create the share security tdb.
122 ********************************************************************/
124 static TDB_CONTEXT *share_tdb; /* used for share security descriptors */
125 #define SHARE_DATABASE_VERSION_V1 1
126 #define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
128 BOOL share_info_db_init(void)
130 static pid_t local_pid;
131 const char *vstring = "INFO/version";
132 int32 vers_id;
134 if (share_tdb && local_pid == sys_getpid())
135 return True;
136 share_tdb = tdb_open_log(lock_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
137 if (!share_tdb) {
138 DEBUG(0,("Failed to open share info database %s (%s)\n",
139 lock_path("share_info.tdb"), strerror(errno) ));
140 return False;
143 local_pid = sys_getpid();
145 /* handle a Samba upgrade */
146 tdb_lock_bystring(share_tdb, vstring, 0);
148 /* Cope with byte-reversed older versions of the db. */
149 vers_id = tdb_fetch_int32(share_tdb, vstring);
150 if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
151 /* Written on a bigendian machine with old fetch_int code. Save as le. */
152 tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
153 vers_id = SHARE_DATABASE_VERSION_V2;
156 if (vers_id != SHARE_DATABASE_VERSION_V2) {
157 tdb_traverse(share_tdb, tdb_traverse_delete_fn, NULL);
158 tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
160 tdb_unlock_bystring(share_tdb, vstring);
162 message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated);
164 return True;
167 /*******************************************************************
168 Fake up a Everyone, full access as a default.
169 ********************************************************************/
171 static SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, int snum, size_t *psize)
173 extern DOM_SID global_sid_World;
174 extern struct generic_mapping file_generic_mapping;
175 SEC_ACCESS sa;
176 SEC_ACE ace;
177 SEC_ACL *psa = NULL;
178 SEC_DESC *psd = NULL;
179 uint32 def_access = GENERIC_ALL_ACCESS;
181 se_map_generic(&def_access, &file_generic_mapping);
183 init_sec_access(&sa, GENERIC_ALL_ACCESS | def_access );
184 init_sec_ace(&ace, &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
186 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 1, &ace)) != NULL) {
187 psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, psa, psize);
190 if (!psd) {
191 DEBUG(0,("get_share_security: Failed to make SEC_DESC.\n"));
192 return NULL;
195 return psd;
198 /*******************************************************************
199 Pull a security descriptor from the share tdb.
200 ********************************************************************/
202 static SEC_DESC *get_share_security( TALLOC_CTX *ctx, int snum, size_t *psize)
204 prs_struct ps;
205 fstring key;
206 SEC_DESC *psd = NULL;
208 *psize = 0;
210 /* Fetch security descriptor from tdb */
212 slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
214 if (tdb_prs_fetch(share_tdb, key, &ps, ctx)!=0 ||
215 !sec_io_desc("get_share_security", &psd, &ps, 1)) {
217 DEBUG(4,("get_share_security: using default secdesc for %s\n", lp_servicename(snum) ));
219 return get_share_security_default(ctx, snum, psize);
222 if (psd)
223 *psize = sec_desc_size(psd);
225 prs_mem_free(&ps);
226 return psd;
229 /*******************************************************************
230 Store a security descriptor in the share db.
231 ********************************************************************/
233 static BOOL set_share_security(TALLOC_CTX *ctx, const char *share_name, SEC_DESC *psd)
235 prs_struct ps;
236 TALLOC_CTX *mem_ctx = NULL;
237 fstring key;
238 BOOL ret = False;
240 mem_ctx = talloc_init("set_share_security");
241 if (mem_ctx == NULL)
242 return False;
244 prs_init(&ps, (uint32)sec_desc_size(psd), mem_ctx, MARSHALL);
246 if (!sec_io_desc("share_security", &psd, &ps, 1))
247 goto out;
249 slprintf(key, sizeof(key)-1, "SECDESC/%s", share_name);
251 if (tdb_prs_store(share_tdb, key, &ps)==0) {
252 ret = True;
253 DEBUG(5,("set_share_security: stored secdesc for %s\n", share_name ));
254 } else {
255 DEBUG(1,("set_share_security: Failed to store secdesc for %s\n", share_name ));
258 /* Free malloc'ed memory */
260 out:
262 prs_mem_free(&ps);
263 if (mem_ctx)
264 talloc_destroy(mem_ctx);
265 return ret;
268 /*******************************************************************
269 Delete a security descriptor.
270 ********************************************************************/
272 static BOOL delete_share_security(int snum)
274 TDB_DATA kbuf;
275 fstring key;
277 slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
278 kbuf.dptr = key;
279 kbuf.dsize = strlen(key)+1;
281 if (tdb_delete(share_tdb, kbuf) != 0) {
282 DEBUG(0,("delete_share_security: Failed to delete entry for share %s\n",
283 lp_servicename(snum) ));
284 return False;
287 return True;
290 /*******************************************************************
291 Map any generic bits to file specific bits.
292 ********************************************************************/
294 void map_generic_share_sd_bits(SEC_DESC *psd)
296 extern struct generic_mapping file_generic_mapping;
297 int i;
298 SEC_ACL *ps_dacl = NULL;
300 if (!psd)
301 return;
303 ps_dacl = psd->dacl;
304 if (!ps_dacl)
305 return;
307 for (i = 0; i < ps_dacl->num_aces; i++) {
308 SEC_ACE *psa = &ps_dacl->ace[i];
309 uint32 orig_mask = psa->info.mask;
311 se_map_generic(&psa->info.mask, &file_generic_mapping);
312 psa->info.mask |= orig_mask;
316 /*******************************************************************
317 Can this user access with share with the required permissions ?
318 ********************************************************************/
320 BOOL share_access_check(connection_struct *conn, int snum, user_struct *vuser, uint32 desired_access)
322 uint32 granted;
323 NTSTATUS status;
324 TALLOC_CTX *mem_ctx = NULL;
325 SEC_DESC *psd = NULL;
326 size_t sd_size;
327 NT_USER_TOKEN *token = NULL;
328 BOOL ret = True;
330 mem_ctx = talloc_init("share_access_check");
331 if (mem_ctx == NULL)
332 return False;
334 psd = get_share_security(mem_ctx, snum, &sd_size);
336 if (!psd)
337 goto out;
339 if (conn->nt_user_token)
340 token = conn->nt_user_token;
341 else
342 token = vuser->nt_user_token;
344 ret = se_access_check(psd, token, desired_access, &granted, &status);
346 out:
348 talloc_destroy(mem_ctx);
350 return ret;
353 /*******************************************************************
354 Fill in a share info level 501 structure.
355 ********************************************************************/
357 static void init_srv_share_info_501(pipes_struct *p, SRV_SHARE_INFO_501 *sh501, int snum)
359 pstring remark;
361 const char *net_name = lp_servicename(snum);
362 pstrcpy(remark, lp_comment(snum));
363 standard_sub_conn(p->conn, remark, sizeof(remark));
365 init_srv_share_info501(&sh501->info_501, net_name, get_share_type(snum), remark, (lp_csc_policy(snum) << 4));
366 init_srv_share_info501_str(&sh501->info_501_str, net_name, remark);
369 /*******************************************************************
370 Fill in a share info level 502 structure.
371 ********************************************************************/
373 static void init_srv_share_info_502(pipes_struct *p, SRV_SHARE_INFO_502 *sh502, int snum)
375 pstring net_name;
376 pstring remark;
377 pstring path;
378 pstring passwd;
379 SEC_DESC *sd;
380 size_t sd_size;
381 TALLOC_CTX *ctx = p->mem_ctx;
384 ZERO_STRUCTP(sh502);
386 pstrcpy(net_name, lp_servicename(snum));
387 pstrcpy(remark, lp_comment(snum));
388 standard_sub_conn(p->conn, remark,sizeof(remark));
389 pstrcpy(path, "C:");
390 pstrcat(path, lp_pathname(snum));
393 * Change / to \\ so that win2k will see it as a valid path. This was added to
394 * enable use of browsing in win2k add share dialog.
397 string_replace(path, '/', '\\');
399 pstrcpy(passwd, "");
401 sd = get_share_security(ctx, snum, &sd_size);
403 init_srv_share_info502(&sh502->info_502, net_name, get_share_type(snum), remark, 0, 0xffffffff, 1, path, passwd, sd, sd_size);
404 init_srv_share_info502_str(&sh502->info_502_str, net_name, remark, path, passwd, sd, sd_size);
407 /***************************************************************************
408 Fill in a share info level 1004 structure.
409 ***************************************************************************/
411 static void init_srv_share_info_1004(pipes_struct *p, SRV_SHARE_INFO_1004* sh1004, int snum)
413 pstring remark;
415 pstrcpy(remark, lp_comment(snum));
416 standard_sub_conn(p->conn, remark, sizeof(remark));
418 ZERO_STRUCTP(sh1004);
420 init_srv_share_info1004(&sh1004->info_1004, remark);
421 init_srv_share_info1004_str(&sh1004->info_1004_str, remark);
424 /***************************************************************************
425 Fill in a share info level 1005 structure.
426 ***************************************************************************/
428 static void init_srv_share_info_1005(pipes_struct *p, SRV_SHARE_INFO_1005* sh1005, int snum)
430 sh1005->share_info_flags = 0;
432 if(lp_host_msdfs() && lp_msdfs_root(snum))
433 sh1005->share_info_flags |=
434 SHARE_1005_IN_DFS | SHARE_1005_DFS_ROOT;
435 sh1005->share_info_flags |=
436 lp_csc_policy(snum) << SHARE_1005_CSC_POLICY_SHIFT;
438 /***************************************************************************
439 Fill in a share info level 1006 structure.
440 ***************************************************************************/
442 static void init_srv_share_info_1006(pipes_struct *p, SRV_SHARE_INFO_1006* sh1006, int snum)
444 sh1006->max_uses = -1;
447 /***************************************************************************
448 Fill in a share info level 1007 structure.
449 ***************************************************************************/
451 static void init_srv_share_info_1007(pipes_struct *p, SRV_SHARE_INFO_1007* sh1007, int snum)
453 pstring alternate_directory_name = "";
454 uint32 flags = 0;
456 ZERO_STRUCTP(sh1007);
458 init_srv_share_info1007(&sh1007->info_1007, flags, alternate_directory_name);
459 init_srv_share_info1007_str(&sh1007->info_1007_str, alternate_directory_name);
462 /*******************************************************************
463 Fill in a share info level 1501 structure.
464 ********************************************************************/
466 static void init_srv_share_info_1501(pipes_struct *p, SRV_SHARE_INFO_1501 *sh1501, int snum)
468 SEC_DESC *sd;
469 size_t sd_size;
470 TALLOC_CTX *ctx = p->mem_ctx;
472 ZERO_STRUCTP(sh1501);
474 sd = get_share_security(ctx, snum, &sd_size);
476 sh1501->sdb = make_sec_desc_buf(p->mem_ctx, sd_size, sd);
479 /*******************************************************************
480 True if it ends in '$'.
481 ********************************************************************/
483 static BOOL is_hidden_share(int snum)
485 const char *net_name = lp_servicename(snum);
487 return (net_name[strlen(net_name) - 1] == '$') ? True : False;
490 /*******************************************************************
491 Fill in a share info structure.
492 ********************************************************************/
494 static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
495 uint32 info_level, uint32 *resume_hnd, uint32 *total_entries, BOOL all_shares)
497 int num_entries = 0;
498 int num_services = lp_numservices();
499 int snum;
500 TALLOC_CTX *ctx = p->mem_ctx;
502 DEBUG(5,("init_srv_share_info_ctr\n"));
504 ZERO_STRUCTPN(ctr);
506 ctr->info_level = ctr->switch_value = info_level;
507 *resume_hnd = 0;
509 /* Count the number of entries. */
510 for (snum = 0; snum < num_services; snum++) {
511 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) )
512 num_entries++;
515 *total_entries = num_entries;
516 ctr->num_entries2 = ctr->num_entries = num_entries;
517 ctr->ptr_share_info = ctr->ptr_entries = 1;
519 if (!num_entries)
520 return True;
522 switch (info_level) {
523 case 0:
525 SRV_SHARE_INFO_0 *info0 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_0, num_entries);
526 int i = 0;
528 if (!info0) {
529 return False;
532 for (snum = *resume_hnd; snum < num_services; snum++) {
533 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
534 init_srv_share_info_0(p, &info0[i++], snum);
538 ctr->share.info0 = info0;
539 break;
543 case 1:
545 SRV_SHARE_INFO_1 *info1 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1, num_entries);
546 int i = 0;
548 if (!info1) {
549 return False;
552 for (snum = *resume_hnd; snum < num_services; snum++) {
553 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
554 init_srv_share_info_1(p, &info1[i++], snum);
558 ctr->share.info1 = info1;
559 break;
562 case 2:
564 SRV_SHARE_INFO_2 *info2 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_2, num_entries);
565 int i = 0;
567 if (!info2) {
568 return False;
571 for (snum = *resume_hnd; snum < num_services; snum++) {
572 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
573 init_srv_share_info_2(p, &info2[i++], snum);
577 ctr->share.info2 = info2;
578 break;
581 case 501:
583 SRV_SHARE_INFO_501 *info501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_501, num_entries);
584 int i = 0;
586 if (!info501) {
587 return False;
590 for (snum = *resume_hnd; snum < num_services; snum++) {
591 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
592 init_srv_share_info_501(p, &info501[i++], snum);
596 ctr->share.info501 = info501;
597 break;
600 case 502:
602 SRV_SHARE_INFO_502 *info502 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_502, num_entries);
603 int i = 0;
605 if (!info502) {
606 return False;
609 for (snum = *resume_hnd; snum < num_services; snum++) {
610 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
611 init_srv_share_info_502(p, &info502[i++], snum);
615 ctr->share.info502 = info502;
616 break;
619 /* here for completeness but not currently used with enum (1004 - 1501)*/
621 case 1004:
623 SRV_SHARE_INFO_1004 *info1004 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1004, num_entries);
624 int i = 0;
626 if (!info1004) {
627 return False;
630 for (snum = *resume_hnd; snum < num_services; snum++) {
631 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
632 init_srv_share_info_1004(p, &info1004[i++], snum);
636 ctr->share.info1004 = info1004;
637 break;
640 case 1005:
642 SRV_SHARE_INFO_1005 *info1005 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1005, num_entries);
643 int i = 0;
645 if (!info1005) {
646 return False;
649 for (snum = *resume_hnd; snum < num_services; snum++) {
650 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
651 init_srv_share_info_1005(p, &info1005[i++], snum);
655 ctr->share.info1005 = info1005;
656 break;
659 case 1006:
661 SRV_SHARE_INFO_1006 *info1006 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1006, num_entries);
662 int i = 0;
664 if (!info1006) {
665 return False;
668 for (snum = *resume_hnd; snum < num_services; snum++) {
669 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
670 init_srv_share_info_1006(p, &info1006[i++], snum);
674 ctr->share.info1006 = info1006;
675 break;
678 case 1007:
680 SRV_SHARE_INFO_1007 *info1007 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1007, num_entries);
681 int i = 0;
683 if (!info1007) {
684 return False;
687 for (snum = *resume_hnd; snum < num_services; snum++) {
688 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
689 init_srv_share_info_1007(p, &info1007[i++], snum);
693 ctr->share.info1007 = info1007;
694 break;
697 case 1501:
699 SRV_SHARE_INFO_1501 *info1501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1501, num_entries);
700 int i = 0;
702 if (!info1501) {
703 return False;
706 for (snum = *resume_hnd; snum < num_services; snum++) {
707 if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
708 init_srv_share_info_1501(p, &info1501[i++], snum);
712 ctr->share.info1501 = info1501;
713 break;
715 default:
716 DEBUG(5,("init_srv_share_info_ctr: unsupported switch value %d\n", info_level));
717 return False;
720 return True;
723 /*******************************************************************
724 Inits a SRV_R_NET_SHARE_ENUM structure.
725 ********************************************************************/
727 static void init_srv_r_net_share_enum(pipes_struct *p, SRV_R_NET_SHARE_ENUM *r_n,
728 uint32 info_level, uint32 resume_hnd, BOOL all)
730 DEBUG(5,("init_srv_r_net_share_enum: %d\n", __LINE__));
732 if (init_srv_share_info_ctr(p, &r_n->ctr, info_level,
733 &resume_hnd, &r_n->total_entries, all)) {
734 r_n->status = WERR_OK;
735 } else {
736 r_n->status = WERR_UNKNOWN_LEVEL;
739 init_enum_hnd(&r_n->enum_hnd, resume_hnd);
742 /*******************************************************************
743 Inits a SRV_R_NET_SHARE_GET_INFO structure.
744 ********************************************************************/
746 static void init_srv_r_net_share_get_info(pipes_struct *p, SRV_R_NET_SHARE_GET_INFO *r_n,
747 char *share_name, uint32 info_level)
749 WERROR status = WERR_OK;
750 int snum;
752 DEBUG(5,("init_srv_r_net_share_get_info: %d\n", __LINE__));
754 r_n->info.switch_value = info_level;
756 snum = find_service(share_name);
758 if (snum >= 0) {
759 switch (info_level) {
760 case 0:
761 init_srv_share_info_0(p, &r_n->info.share.info0, snum);
762 break;
763 case 1:
764 init_srv_share_info_1(p, &r_n->info.share.info1, snum);
765 break;
766 case 2:
767 init_srv_share_info_2(p, &r_n->info.share.info2, snum);
768 break;
769 case 501:
770 init_srv_share_info_501(p, &r_n->info.share.info501, snum);
771 break;
772 case 502:
773 init_srv_share_info_502(p, &r_n->info.share.info502, snum);
774 break;
776 /* here for completeness */
777 case 1004:
778 init_srv_share_info_1004(p, &r_n->info.share.info1004, snum);
779 break;
780 case 1005:
781 init_srv_share_info_1005(p, &r_n->info.share.info1005, snum);
782 break;
784 /* here for completeness 1006 - 1501 */
785 case 1006:
786 init_srv_share_info_1006(p, &r_n->info.share.info1006, snum);
787 break;
788 case 1007:
789 init_srv_share_info_1007(p, &r_n->info.share.info1007, snum);
790 break;
791 case 1501:
792 init_srv_share_info_1501(p, &r_n->info.share.info1501, snum);
793 break;
794 default:
795 DEBUG(5,("init_srv_net_share_get_info: unsupported switch value %d\n", info_level));
796 status = WERR_UNKNOWN_LEVEL;
797 break;
799 } else {
800 status = WERR_INVALID_NAME;
803 r_n->info.ptr_share_ctr = W_ERROR_IS_OK(status) ? 1 : 0;
804 r_n->status = status;
807 /*******************************************************************
808 fill in a sess info level 1 structure.
809 ********************************************************************/
811 static void init_srv_sess_0_info(SESS_INFO_0 *se0, SESS_INFO_0_STR *str0, char *name)
813 init_srv_sess_info0(se0, name);
814 init_srv_sess_info0_str(str0, name);
817 /*******************************************************************
818 fill in a sess info level 0 structure.
819 ********************************************************************/
821 static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *stot)
823 struct sessionid *session_list;
824 uint32 num_entries = 0;
825 (*stot) = list_sessions(&session_list);
827 if (ss0 == NULL) {
828 (*snum) = 0;
829 SAFE_FREE(session_list);
830 return;
833 DEBUG(5,("init_srv_sess_0_ss0\n"));
835 if (snum) {
836 for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++) {
837 init_srv_sess_0_info(&ss0->info_0[num_entries],
838 &ss0->info_0_str[num_entries], session_list[(*snum)].remote_machine);
840 /* move on to creating next session */
841 /* move on to creating next sess */
842 num_entries++;
845 ss0->num_entries_read = num_entries;
846 ss0->ptr_sess_info = num_entries > 0 ? 1 : 0;
847 ss0->num_entries_read2 = num_entries;
849 if ((*snum) >= (*stot)) {
850 (*snum) = 0;
853 } else {
854 ss0->num_entries_read = 0;
855 ss0->ptr_sess_info = 0;
856 ss0->num_entries_read2 = 0;
858 SAFE_FREE(session_list);
861 /*******************************************************************
862 fill in a sess info level 1 structure.
863 ********************************************************************/
865 static void init_srv_sess_1_info(SESS_INFO_1 *se1, SESS_INFO_1_STR *str1,
866 char *name, char *user,
867 uint32 num_opens,
868 uint32 open_time, uint32 idle_time,
869 uint32 usr_flgs)
871 init_srv_sess_info1(se1 , name, user, num_opens, open_time, idle_time, usr_flgs);
872 init_srv_sess_info1_str(str1, name, user);
875 /*******************************************************************
876 fill in a sess info level 1 structure.
877 ********************************************************************/
879 static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *stot)
881 struct sessionid *session_list;
882 uint32 num_entries = 0;
883 (*stot) = list_sessions(&session_list);
885 if (ss1 == NULL) {
886 (*snum) = 0;
887 SAFE_FREE(session_list);
888 return;
891 DEBUG(5,("init_srv_sess_1_ss1\n"));
893 if (snum) {
894 for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++) {
895 init_srv_sess_1_info(&ss1->info_1[num_entries],
896 &ss1->info_1_str[num_entries],
897 session_list[*snum].remote_machine,
898 session_list[*snum].username,
899 1, 10, 5, 0);
901 /* move on to creating next session */
902 /* move on to creating next sess */
903 num_entries++;
906 ss1->num_entries_read = num_entries;
907 ss1->ptr_sess_info = num_entries > 0 ? 1 : 0;
908 ss1->num_entries_read2 = num_entries;
910 if ((*snum) >= (*stot)) {
911 (*snum) = 0;
914 } else {
915 ss1->num_entries_read = 0;
916 ss1->ptr_sess_info = 0;
917 ss1->num_entries_read2 = 0;
919 (*stot) = 0;
923 /*******************************************************************
924 makes a SRV_R_NET_SESS_ENUM structure.
925 ********************************************************************/
927 static WERROR init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
928 int switch_value, uint32 *resume_hnd, uint32 *total_entries)
930 WERROR status = WERR_OK;
931 DEBUG(5,("init_srv_sess_info_ctr: %d\n", __LINE__));
933 ctr->switch_value = switch_value;
935 switch (switch_value) {
936 case 0:
937 init_srv_sess_info_0(&(ctr->sess.info0), resume_hnd, total_entries);
938 ctr->ptr_sess_ctr = 1;
939 break;
940 case 1:
941 init_srv_sess_info_1(&(ctr->sess.info1), resume_hnd, total_entries);
942 ctr->ptr_sess_ctr = 1;
943 break;
944 default:
945 DEBUG(5,("init_srv_sess_info_ctr: unsupported switch value %d\n", switch_value));
946 (*resume_hnd) = 0;
947 (*total_entries) = 0;
948 ctr->ptr_sess_ctr = 0;
949 status = WERR_UNKNOWN_LEVEL;
950 break;
953 return status;
956 /*******************************************************************
957 makes a SRV_R_NET_SESS_ENUM structure.
958 ********************************************************************/
960 static void init_srv_r_net_sess_enum(SRV_R_NET_SESS_ENUM *r_n,
961 uint32 resume_hnd, int sess_level, int switch_value)
963 DEBUG(5,("init_srv_r_net_sess_enum: %d\n", __LINE__));
965 r_n->sess_level = sess_level;
967 if (sess_level == -1)
968 r_n->status = WERR_UNKNOWN_LEVEL;
969 else
970 r_n->status = init_srv_sess_info_ctr(r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
972 if (!W_ERROR_IS_OK(r_n->status))
973 resume_hnd = 0;
975 init_enum_hnd(&r_n->enum_hnd, resume_hnd);
978 /*******************************************************************
979 fill in a conn info level 0 structure.
980 ********************************************************************/
982 static void init_srv_conn_info_0(SRV_CONN_INFO_0 *ss0, uint32 *snum, uint32 *stot)
984 uint32 num_entries = 0;
985 (*stot) = 1;
987 if (ss0 == NULL) {
988 (*snum) = 0;
989 return;
992 DEBUG(5,("init_srv_conn_0_ss0\n"));
994 if (snum) {
995 for (; (*snum) < (*stot) && num_entries < MAX_CONN_ENTRIES; (*snum)++) {
997 init_srv_conn_info0(&ss0->info_0[num_entries], (*stot));
999 /* move on to creating next connection */
1000 /* move on to creating next conn */
1001 num_entries++;
1004 ss0->num_entries_read = num_entries;
1005 ss0->ptr_conn_info = num_entries > 0 ? 1 : 0;
1006 ss0->num_entries_read2 = num_entries;
1008 if ((*snum) >= (*stot)) {
1009 (*snum) = 0;
1012 } else {
1013 ss0->num_entries_read = 0;
1014 ss0->ptr_conn_info = 0;
1015 ss0->num_entries_read2 = 0;
1017 (*stot) = 0;
1021 /*******************************************************************
1022 fill in a conn info level 1 structure.
1023 ********************************************************************/
1025 static void init_srv_conn_1_info(CONN_INFO_1 *se1, CONN_INFO_1_STR *str1,
1026 uint32 id, uint32 type,
1027 uint32 num_opens, uint32 num_users, uint32 open_time,
1028 const char *usr_name, const char *net_name)
1030 init_srv_conn_info1(se1 , id, type, num_opens, num_users, open_time, usr_name, net_name);
1031 init_srv_conn_info1_str(str1, usr_name, net_name);
1034 /*******************************************************************
1035 fill in a conn info level 1 structure.
1036 ********************************************************************/
1038 static void init_srv_conn_info_1(SRV_CONN_INFO_1 *ss1, uint32 *snum, uint32 *stot)
1040 uint32 num_entries = 0;
1041 (*stot) = 1;
1043 if (ss1 == NULL) {
1044 (*snum) = 0;
1045 return;
1048 DEBUG(5,("init_srv_conn_1_ss1\n"));
1050 if (snum) {
1051 for (; (*snum) < (*stot) && num_entries < MAX_CONN_ENTRIES; (*snum)++) {
1052 init_srv_conn_1_info(&ss1->info_1[num_entries],
1053 &ss1->info_1_str[num_entries],
1054 (*stot), 0x3, 1, 1, 3,"dummy_user", "IPC$");
1056 /* move on to creating next connection */
1057 /* move on to creating next conn */
1058 num_entries++;
1061 ss1->num_entries_read = num_entries;
1062 ss1->ptr_conn_info = num_entries > 0 ? 1 : 0;
1063 ss1->num_entries_read2 = num_entries;
1066 if ((*snum) >= (*stot)) {
1067 (*snum) = 0;
1070 } else {
1071 ss1->num_entries_read = 0;
1072 ss1->ptr_conn_info = 0;
1073 ss1->num_entries_read2 = 0;
1075 (*stot) = 0;
1079 /*******************************************************************
1080 makes a SRV_R_NET_CONN_ENUM structure.
1081 ********************************************************************/
1083 static WERROR init_srv_conn_info_ctr(SRV_CONN_INFO_CTR *ctr,
1084 int switch_value, uint32 *resume_hnd, uint32 *total_entries)
1086 WERROR status = WERR_OK;
1087 DEBUG(5,("init_srv_conn_info_ctr: %d\n", __LINE__));
1089 ctr->switch_value = switch_value;
1091 switch (switch_value) {
1092 case 0:
1093 init_srv_conn_info_0(&ctr->conn.info0, resume_hnd, total_entries);
1094 ctr->ptr_conn_ctr = 1;
1095 break;
1096 case 1:
1097 init_srv_conn_info_1(&ctr->conn.info1, resume_hnd, total_entries);
1098 ctr->ptr_conn_ctr = 1;
1099 break;
1100 default:
1101 DEBUG(5,("init_srv_conn_info_ctr: unsupported switch value %d\n", switch_value));
1102 (*resume_hnd = 0);
1103 (*total_entries) = 0;
1104 ctr->ptr_conn_ctr = 0;
1105 status = WERR_UNKNOWN_LEVEL;
1106 break;
1109 return status;
1112 /*******************************************************************
1113 makes a SRV_R_NET_CONN_ENUM structure.
1114 ********************************************************************/
1116 static void init_srv_r_net_conn_enum(SRV_R_NET_CONN_ENUM *r_n,
1117 uint32 resume_hnd, int conn_level, int switch_value)
1119 DEBUG(5,("init_srv_r_net_conn_enum: %d\n", __LINE__));
1121 r_n->conn_level = conn_level;
1122 if (conn_level == -1)
1123 r_n->status = WERR_UNKNOWN_LEVEL;
1124 else
1125 r_n->status = init_srv_conn_info_ctr(r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
1127 if (!W_ERROR_IS_OK(r_n->status))
1128 resume_hnd = 0;
1130 init_enum_hnd(&r_n->enum_hnd, resume_hnd);
1133 /*******************************************************************
1134 makes a SRV_R_NET_FILE_ENUM structure.
1135 ********************************************************************/
1137 static WERROR init_srv_file_info_ctr(pipes_struct *p, SRV_FILE_INFO_CTR *ctr,
1138 int switch_value, uint32 *resume_hnd,
1139 uint32 *total_entries)
1141 WERROR status = WERR_OK;
1142 TALLOC_CTX *ctx = p->mem_ctx;
1143 DEBUG(5,("init_srv_file_info_ctr: %d\n", __LINE__));
1144 *total_entries = 1; /* dummy entries only, for */
1146 ctr->switch_value = switch_value;
1147 ctr->num_entries = *total_entries - *resume_hnd;
1148 ctr->num_entries2 = ctr->num_entries;
1150 switch (switch_value) {
1151 case 3: {
1152 int i;
1153 if (*total_entries > 0) {
1154 ctr->ptr_entries = 1;
1155 ctr->file.info3 = TALLOC_ARRAY(ctx, SRV_FILE_INFO_3, ctr->num_entries);
1157 for (i=0 ;i<ctr->num_entries;i++) {
1158 init_srv_file_info3(&ctr->file.info3[i].info_3, i+*resume_hnd, 0x35, 0, "\\PIPE\\samr", "dummy user");
1159 init_srv_file_info3_str(&ctr->file.info3[i].info_3_str, "\\PIPE\\samr", "dummy user");
1162 ctr->ptr_file_info = 1;
1163 *resume_hnd = 0;
1164 break;
1166 default:
1167 DEBUG(5,("init_srv_file_info_ctr: unsupported switch value %d\n", switch_value));
1168 (*resume_hnd = 0);
1169 (*total_entries) = 0;
1170 ctr->ptr_entries = 0;
1171 status = WERR_UNKNOWN_LEVEL;
1172 break;
1175 return status;
1178 /*******************************************************************
1179 makes a SRV_R_NET_FILE_ENUM structure.
1180 ********************************************************************/
1182 static void init_srv_r_net_file_enum(pipes_struct *p, SRV_R_NET_FILE_ENUM *r_n,
1183 uint32 resume_hnd, int file_level, int switch_value)
1185 DEBUG(5,("init_srv_r_net_file_enum: %d\n", __LINE__));
1187 r_n->file_level = file_level;
1188 if (file_level == 0)
1189 r_n->status = WERR_UNKNOWN_LEVEL;
1190 else
1191 r_n->status = init_srv_file_info_ctr(p, &r_n->ctr, switch_value, &resume_hnd, &(r_n->total_entries));
1193 if (!W_ERROR_IS_OK(r_n->status))
1194 resume_hnd = 0;
1196 init_enum_hnd(&r_n->enum_hnd, resume_hnd);
1199 /*******************************************************************
1200 net server get info
1201 ********************************************************************/
1203 WERROR _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
1205 WERROR status = WERR_OK;
1206 SRV_INFO_CTR *ctr = TALLOC_P(p->mem_ctx, SRV_INFO_CTR);
1208 if (!ctr)
1209 return WERR_NOMEM;
1211 ZERO_STRUCTP(ctr);
1213 DEBUG(5,("srv_net_srv_get_info: %d\n", __LINE__));
1215 if (!pipe_access_check(p)) {
1216 DEBUG(3, ("access denied to srv_net_srv_get_info\n"));
1217 return WERR_ACCESS_DENIED;
1220 switch (q_u->switch_value) {
1222 /* Technically level 102 should only be available to
1223 Administrators but there isn't anything super-secret
1224 here, as most of it is made up. */
1226 case 102:
1227 init_srv_info_102(&ctr->srv.sv102,
1228 500, global_myname(),
1229 string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH),
1230 lp_major_announce_version(), lp_minor_announce_version(),
1231 lp_default_server_announce(),
1232 0xffffffff, /* users */
1233 0xf, /* disc */
1234 0, /* hidden */
1235 240, /* announce */
1236 3000, /* announce delta */
1237 100000, /* licenses */
1238 "c:\\"); /* user path */
1239 break;
1240 case 101:
1241 init_srv_info_101(&ctr->srv.sv101,
1242 500, global_myname(),
1243 lp_major_announce_version(), lp_minor_announce_version(),
1244 lp_default_server_announce(),
1245 string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
1246 break;
1247 case 100:
1248 init_srv_info_100(&ctr->srv.sv100, 500, global_myname());
1249 break;
1250 default:
1251 status = WERR_UNKNOWN_LEVEL;
1252 break;
1255 /* set up the net server get info structure */
1256 init_srv_r_net_srv_get_info(r_u, q_u->switch_value, ctr, status);
1258 DEBUG(5,("srv_net_srv_get_info: %d\n", __LINE__));
1260 return r_u->status;
1263 /*******************************************************************
1264 net server set info
1265 ********************************************************************/
1267 WERROR _srv_net_srv_set_info(pipes_struct *p, SRV_Q_NET_SRV_SET_INFO *q_u, SRV_R_NET_SRV_SET_INFO *r_u)
1269 WERROR status = WERR_OK;
1271 DEBUG(5,("srv_net_srv_set_info: %d\n", __LINE__));
1273 /* Set up the net server set info structure. */
1275 init_srv_r_net_srv_set_info(r_u, 0x0, status);
1277 DEBUG(5,("srv_net_srv_set_info: %d\n", __LINE__));
1279 return r_u->status;
1282 /*******************************************************************
1283 net file enum
1284 ********************************************************************/
1286 WERROR _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u)
1288 DEBUG(5,("srv_net_file_enum: %d\n", __LINE__));
1290 /* set up the */
1291 init_srv_r_net_file_enum(p, r_u,
1292 get_enum_hnd(&q_u->enum_hnd),
1293 q_u->file_level,
1294 q_u->ctr.switch_value);
1296 DEBUG(5,("srv_net_file_enum: %d\n", __LINE__));
1298 return r_u->status;
1301 /*******************************************************************
1302 net conn enum
1303 ********************************************************************/
1305 WERROR _srv_net_conn_enum(pipes_struct *p, SRV_Q_NET_CONN_ENUM *q_u, SRV_R_NET_CONN_ENUM *r_u)
1307 DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
1309 r_u->ctr = TALLOC_P(p->mem_ctx, SRV_CONN_INFO_CTR);
1310 if (!r_u->ctr)
1311 return WERR_NOMEM;
1313 ZERO_STRUCTP(r_u->ctr);
1315 /* set up the */
1316 init_srv_r_net_conn_enum(r_u,
1317 get_enum_hnd(&q_u->enum_hnd),
1318 q_u->conn_level,
1319 q_u->ctr->switch_value);
1321 DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
1323 return r_u->status;
1326 /*******************************************************************
1327 net sess enum
1328 ********************************************************************/
1330 WERROR _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET_SESS_ENUM *r_u)
1332 DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
1334 r_u->ctr = TALLOC_P(p->mem_ctx, SRV_SESS_INFO_CTR);
1335 if (!r_u->ctr)
1336 return WERR_NOMEM;
1338 ZERO_STRUCTP(r_u->ctr);
1340 /* set up the */
1341 init_srv_r_net_sess_enum(r_u,
1342 get_enum_hnd(&q_u->enum_hnd),
1343 q_u->sess_level,
1344 q_u->ctr->switch_value);
1346 DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
1348 return r_u->status;
1351 /*******************************************************************
1352 Net share enum all.
1353 ********************************************************************/
1355 WERROR _srv_net_share_enum_all(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
1357 DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
1359 if (!pipe_access_check(p)) {
1360 DEBUG(3, ("access denied to srv_net_share_enum_all\n"));
1361 return WERR_ACCESS_DENIED;
1364 /* Create the list of shares for the response. */
1365 init_srv_r_net_share_enum(p, r_u,
1366 q_u->ctr.info_level,
1367 get_enum_hnd(&q_u->enum_hnd), True);
1369 DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
1371 return r_u->status;
1374 /*******************************************************************
1375 Net share enum.
1376 ********************************************************************/
1378 WERROR _srv_net_share_enum(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
1380 DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
1382 if (!pipe_access_check(p)) {
1383 DEBUG(3, ("access denied to srv_net_share_enum\n"));
1384 return WERR_ACCESS_DENIED;
1387 /* Create the list of shares for the response. */
1388 init_srv_r_net_share_enum(p, r_u,
1389 q_u->ctr.info_level,
1390 get_enum_hnd(&q_u->enum_hnd), False);
1392 DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
1394 return r_u->status;
1397 /*******************************************************************
1398 Net share get info.
1399 ********************************************************************/
1401 WERROR _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u, SRV_R_NET_SHARE_GET_INFO *r_u)
1403 fstring share_name;
1405 DEBUG(5,("_srv_net_share_get_info: %d\n", __LINE__));
1407 /* Create the list of shares for the response. */
1408 unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));
1409 init_srv_r_net_share_get_info(p, r_u, share_name, q_u->info_level);
1411 DEBUG(5,("_srv_net_share_get_info: %d\n", __LINE__));
1413 return r_u->status;
1416 /*******************************************************************
1417 Check a given DOS pathname is valid for a share.
1418 ********************************************************************/
1420 static char *valid_share_pathname(char *dos_pathname)
1422 pstring saved_pathname;
1423 pstring unix_pathname;
1424 char *ptr;
1425 int ret;
1427 /* Convert any '\' paths to '/' */
1428 unix_format(dos_pathname);
1429 unix_clean_name(dos_pathname);
1431 /* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */
1432 ptr = dos_pathname;
1433 if (strlen(dos_pathname) > 2 && ptr[1] == ':' && ptr[0] != '/')
1434 ptr += 2;
1436 /* Only abolute paths allowed. */
1437 if (*ptr != '/')
1438 return NULL;
1440 /* Can we cd to it ? */
1442 /* First save our current directory. */
1443 if (getcwd(saved_pathname, sizeof(saved_pathname)) == NULL)
1444 return False;
1446 pstrcpy(unix_pathname, ptr);
1448 ret = chdir(unix_pathname);
1450 /* We *MUST* be able to chdir back. Abort if we can't. */
1451 if (chdir(saved_pathname) == -1)
1452 smb_panic("valid_share_pathname: Unable to restore current directory.\n");
1454 return (ret != -1) ? ptr : NULL;
1457 /*******************************************************************
1458 Net share set info. Modify share details.
1459 ********************************************************************/
1461 WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, SRV_R_NET_SHARE_SET_INFO *r_u)
1463 struct current_user user;
1464 pstring command;
1465 fstring share_name;
1466 fstring comment;
1467 pstring pathname;
1468 int type;
1469 int snum;
1470 int ret;
1471 char *ptr;
1472 SEC_DESC *psd = NULL;
1474 DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
1476 unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));
1478 r_u->parm_error = 0;
1480 if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
1481 return WERR_ACCESS_DENIED;
1483 snum = find_service(share_name);
1485 /* Does this share exist ? */
1486 if (snum < 0)
1487 return WERR_INVALID_NAME;
1489 /* No change to printer shares. */
1490 if (lp_print_ok(snum))
1491 return WERR_ACCESS_DENIED;
1493 get_current_user(&user,p);
1495 if (user.uid != sec_initial_uid())
1496 return WERR_ACCESS_DENIED;
1498 switch (q_u->info_level) {
1499 case 1:
1500 pstrcpy(pathname, lp_pathname(snum));
1501 unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment));
1502 type = q_u->info.share.info2.info_2.type;
1503 psd = NULL;
1504 break;
1505 case 2:
1506 unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment));
1507 unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(pathname));
1508 type = q_u->info.share.info2.info_2.type;
1509 psd = NULL;
1510 break;
1511 #if 0
1512 /* not supported on set but here for completeness */
1513 case 501:
1514 unistr2_to_ascii(comment, &q_u->info.share.info501.info_501_str.uni_remark, sizeof(comment));
1515 type = q_u->info.share.info501.info_501.type;
1516 psd = NULL;
1517 break;
1518 #endif
1519 case 502:
1520 unistr2_to_ascii(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(comment));
1521 unistr2_to_ascii(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(pathname));
1522 type = q_u->info.share.info502.info_502.type;
1523 psd = q_u->info.share.info502.info_502_str.sd;
1524 map_generic_share_sd_bits(psd);
1525 break;
1526 case 1004:
1527 pstrcpy(pathname, lp_pathname(snum));
1528 unistr2_to_ascii(comment, &q_u->info.share.info1004.info_1004_str.uni_remark, sizeof(comment));
1529 type = STYPE_DISKTREE;
1530 break;
1531 case 1005:
1532 /* XP re-sets the csc policy even if it wasn't changed by the
1533 user, so we must compare it to see if it's what is set in
1534 smb.conf, so that we can contine other ops like setting
1535 ACLs on a share */
1536 if (((q_u->info.share.info1005.share_info_flags &
1537 SHARE_1005_CSC_POLICY_MASK) >>
1538 SHARE_1005_CSC_POLICY_SHIFT) == lp_csc_policy(snum))
1539 return WERR_OK;
1540 else {
1541 DEBUG(3, ("_srv_net_share_set_info: client is trying to change csc policy from the network; must be done with smb.conf\n"));
1542 return WERR_ACCESS_DENIED;
1544 break;
1545 case 1006:
1546 case 1007:
1547 return WERR_ACCESS_DENIED;
1548 break;
1549 case 1501:
1550 pstrcpy(pathname, lp_pathname(snum));
1551 fstrcpy(comment, lp_comment(snum));
1552 psd = q_u->info.share.info1501.sdb->sec;
1553 map_generic_share_sd_bits(psd);
1554 type = STYPE_DISKTREE;
1555 break;
1556 default:
1557 DEBUG(5,("_srv_net_share_set_info: unsupported switch value %d\n", q_u->info_level));
1558 return WERR_UNKNOWN_LEVEL;
1561 /* We can only modify disk shares. */
1562 if (type != STYPE_DISKTREE)
1563 return WERR_ACCESS_DENIED;
1565 /* Check if the pathname is valid. */
1566 if (!(ptr = valid_share_pathname( pathname )))
1567 return WERR_OBJECT_PATH_INVALID;
1569 /* Ensure share name, pathname and comment don't contain '"' characters. */
1570 string_replace(share_name, '"', ' ');
1571 string_replace(ptr, '"', ' ');
1572 string_replace(comment, '"', ' ');
1574 DEBUG(10,("_srv_net_share_set_info: change share command = %s\n",
1575 lp_change_share_cmd() ? lp_change_share_cmd() : "NULL" ));
1577 /* Only call modify function if something changed. */
1579 if (strcmp(ptr, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) ) {
1580 if (!lp_change_share_cmd() || !*lp_change_share_cmd())
1581 return WERR_ACCESS_DENIED;
1583 slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"",
1584 lp_change_share_cmd(), dyn_CONFIGFILE, share_name, ptr, comment);
1586 DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command ));
1587 if ((ret = smbrun(command, NULL)) != 0) {
1588 DEBUG(0,("_srv_net_share_set_info: Running [%s] returned (%d)\n", command, ret ));
1589 return WERR_ACCESS_DENIED;
1592 /* Tell everyone we updated smb.conf. */
1593 message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
1595 } else {
1596 DEBUG(10,("_srv_net_share_set_info: No change to share name (%s)\n", share_name ));
1599 /* Replace SD if changed. */
1600 if (psd) {
1601 SEC_DESC *old_sd;
1602 size_t sd_size;
1604 old_sd = get_share_security(p->mem_ctx, snum, &sd_size);
1606 if (old_sd && !sec_desc_equal(old_sd, psd)) {
1607 if (!set_share_security(p->mem_ctx, share_name, psd))
1608 DEBUG(0,("_srv_net_share_set_info: Failed to change security info in share %s.\n",
1609 share_name ));
1613 DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
1615 return WERR_OK;
1618 /*******************************************************************
1619 Net share add. Call 'add_share_command "sharename" "pathname" "comment" "read only = xxx"'
1620 ********************************************************************/
1622 WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_SHARE_ADD *r_u)
1624 struct current_user user;
1625 pstring command;
1626 fstring share_name;
1627 fstring comment;
1628 pstring pathname;
1629 int type;
1630 int snum;
1631 int ret;
1632 char *ptr;
1633 SEC_DESC *psd = NULL;
1635 DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));
1637 r_u->parm_error = 0;
1639 get_current_user(&user,p);
1641 if (user.uid != sec_initial_uid()) {
1642 DEBUG(10,("_srv_net_share_add: uid != sec_initial_uid(). Access denied.\n"));
1643 return WERR_ACCESS_DENIED;
1646 if (!lp_add_share_cmd() || !*lp_add_share_cmd()) {
1647 DEBUG(10,("_srv_net_share_add: No add share command\n"));
1648 return WERR_ACCESS_DENIED;
1651 switch (q_u->info_level) {
1652 case 0:
1653 /* No path. Not enough info in a level 0 to do anything. */
1654 return WERR_ACCESS_DENIED;
1655 case 1:
1656 /* Not enough info in a level 1 to do anything. */
1657 return WERR_ACCESS_DENIED;
1658 case 2:
1659 unistr2_to_ascii(share_name, &q_u->info.share.info2.info_2_str.uni_netname, sizeof(share_name));
1660 unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(share_name));
1661 unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(share_name));
1662 type = q_u->info.share.info2.info_2.type;
1663 break;
1664 case 501:
1665 /* No path. Not enough info in a level 501 to do anything. */
1666 return WERR_ACCESS_DENIED;
1667 case 502:
1668 unistr2_to_ascii(share_name, &q_u->info.share.info502.info_502_str.uni_netname, sizeof(share_name));
1669 unistr2_to_ascii(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(share_name));
1670 unistr2_to_ascii(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(share_name));
1671 type = q_u->info.share.info502.info_502.type;
1672 psd = q_u->info.share.info502.info_502_str.sd;
1673 map_generic_share_sd_bits(psd);
1674 break;
1676 /* none of the following contain share names. NetShareAdd does not have a separate parameter for the share name */
1678 case 1004:
1679 case 1005:
1680 case 1006:
1681 case 1007:
1682 return WERR_ACCESS_DENIED;
1683 break;
1684 case 1501:
1685 /* DFS only level. */
1686 return WERR_ACCESS_DENIED;
1687 default:
1688 DEBUG(5,("_srv_net_share_add: unsupported switch value %d\n", q_u->info_level));
1689 return WERR_UNKNOWN_LEVEL;
1692 if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
1693 return WERR_ACCESS_DENIED;
1695 snum = find_service(share_name);
1697 /* Share already exists. */
1698 if (snum >= 0)
1699 return WERR_ALREADY_EXISTS;
1701 /* We can only add disk shares. */
1702 if (type != STYPE_DISKTREE)
1703 return WERR_ACCESS_DENIED;
1705 /* Check if the pathname is valid. */
1706 if (!(ptr = valid_share_pathname( pathname )))
1707 return WERR_OBJECT_PATH_INVALID;
1709 /* Ensure share name, pathname and comment don't contain '"' characters. */
1710 string_replace(share_name, '"', ' ');
1711 string_replace(ptr, '"', ' ');
1712 string_replace(comment, '"', ' ');
1714 slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"",
1715 lp_add_share_cmd(), dyn_CONFIGFILE, share_name, ptr, comment);
1717 DEBUG(10,("_srv_net_share_add: Running [%s]\n", command ));
1718 if ((ret = smbrun(command, NULL)) != 0) {
1719 DEBUG(0,("_srv_net_share_add: Running [%s] returned (%d)\n", command, ret ));
1720 return WERR_ACCESS_DENIED;
1723 if (psd) {
1724 if (!set_share_security(p->mem_ctx, share_name, psd))
1725 DEBUG(0,("_srv_net_share_add: Failed to add security info to share %s.\n",
1726 share_name ));
1729 /* Tell everyone we updated smb.conf. */
1730 message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
1733 * We don't call reload_services() here, the message will
1734 * cause this to be done before the next packet is read
1735 * from the client. JRA.
1738 DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));
1740 return WERR_OK;
1743 /*******************************************************************
1744 Net share delete. Call "delete share command" with the share name as
1745 a parameter.
1746 ********************************************************************/
1748 WERROR _srv_net_share_del(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u)
1750 struct current_user user;
1751 pstring command;
1752 fstring share_name;
1753 int ret;
1754 int snum;
1756 DEBUG(5,("_srv_net_share_del: %d\n", __LINE__));
1758 unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));
1760 if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
1761 return WERR_ACCESS_DENIED;
1763 snum = find_service(share_name);
1765 if (snum < 0)
1766 return WERR_NO_SUCH_SHARE;
1768 /* No change to printer shares. */
1769 if (lp_print_ok(snum))
1770 return WERR_ACCESS_DENIED;
1772 get_current_user(&user,p);
1774 if (user.uid != sec_initial_uid())
1775 return WERR_ACCESS_DENIED;
1777 if (!lp_delete_share_cmd() || !*lp_delete_share_cmd())
1778 return WERR_ACCESS_DENIED;
1780 slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"",
1781 lp_delete_share_cmd(), dyn_CONFIGFILE, lp_servicename(snum));
1783 DEBUG(10,("_srv_net_share_del: Running [%s]\n", command ));
1784 if ((ret = smbrun(command, NULL)) != 0) {
1785 DEBUG(0,("_srv_net_share_del: Running [%s] returned (%d)\n", command, ret ));
1786 return WERR_ACCESS_DENIED;
1789 /* Delete the SD in the database. */
1790 delete_share_security(snum);
1792 /* Tell everyone we updated smb.conf. */
1793 message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
1795 lp_killservice(snum);
1797 return WERR_OK;
1800 WERROR _srv_net_share_del_sticky(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u)
1802 DEBUG(5,("_srv_net_share_del_stick: %d\n", __LINE__));
1804 return _srv_net_share_del(p, q_u, r_u);
1807 /*******************************************************************
1808 time of day
1809 ********************************************************************/
1811 WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET_REMOTE_TOD *r_u)
1813 TIME_OF_DAY_INFO *tod;
1814 struct tm *t;
1815 time_t unixdate = time(NULL);
1817 tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO);
1818 if (!tod)
1819 return WERR_NOMEM;
1821 ZERO_STRUCTP(tod);
1823 r_u->tod = tod;
1824 r_u->ptr_srv_tod = 0x1;
1825 r_u->status = WERR_OK;
1827 DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__));
1829 t = gmtime(&unixdate);
1831 /* set up the */
1832 init_time_of_day_info(tod,
1833 unixdate,
1835 t->tm_hour,
1836 t->tm_min,
1837 t->tm_sec,
1839 TimeDiff(unixdate)/60,
1840 10000,
1841 t->tm_mday,
1842 t->tm_mon + 1,
1843 1900+t->tm_year,
1844 t->tm_wday);
1846 DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__));
1848 return r_u->status;
1851 /***********************************************************************************
1852 Win9x NT tools get security descriptor.
1853 ***********************************************************************************/
1855 WERROR _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDESC *q_u,
1856 SRV_R_NET_FILE_QUERY_SECDESC *r_u)
1858 SEC_DESC *psd = NULL;
1859 size_t sd_size;
1860 DATA_BLOB null_pw;
1861 pstring filename;
1862 pstring qualname;
1863 files_struct *fsp = NULL;
1864 SMB_STRUCT_STAT st;
1865 BOOL bad_path;
1866 int access_mode;
1867 int action;
1868 NTSTATUS nt_status;
1869 struct current_user user;
1870 connection_struct *conn = NULL;
1871 BOOL became_user = False;
1873 ZERO_STRUCT(st);
1875 r_u->status = WERR_OK;
1877 unistr2_to_ascii(qualname, &q_u->uni_qual_name, sizeof(qualname));
1879 /* Null password is ok - we are already an authenticated user... */
1880 null_pw = data_blob(NULL, 0);
1882 get_current_user(&user, p);
1884 become_root();
1885 conn = make_connection(qualname, null_pw, "A:", user.vuid, &nt_status);
1886 unbecome_root();
1888 if (conn == NULL) {
1889 DEBUG(3,("_srv_net_file_query_secdesc: Unable to connect to %s\n", qualname));
1890 r_u->status = ntstatus_to_werror(nt_status);
1891 goto error_exit;
1894 if (!become_user(conn, conn->vuid)) {
1895 DEBUG(0,("_srv_net_file_query_secdesc: Can't become connected user!\n"));
1896 r_u->status = WERR_ACCESS_DENIED;
1897 goto error_exit;
1899 became_user = True;
1901 unistr2_to_ascii(filename, &q_u->uni_file_name, sizeof(filename));
1902 unix_convert(filename, conn, NULL, &bad_path, &st);
1903 if (bad_path) {
1904 DEBUG(3,("_srv_net_file_query_secdesc: bad pathname %s\n", filename));
1905 r_u->status = WERR_ACCESS_DENIED;
1906 goto error_exit;
1909 if (!check_name(filename,conn)) {
1910 DEBUG(3,("_srv_net_file_query_secdesc: can't access %s\n", filename));
1911 r_u->status = WERR_ACCESS_DENIED;
1912 goto error_exit;
1915 fsp = open_file_shared(conn, filename, &st, SET_DENY_MODE(DENY_NONE)|SET_OPEN_MODE(DOS_OPEN_RDONLY),
1916 (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), FILE_ATTRIBUTE_NORMAL, INTERNAL_OPEN_ONLY,
1917 &access_mode, &action);
1919 if (!fsp) {
1920 /* Perhaps it is a directory */
1921 if (errno == EISDIR)
1922 fsp = open_directory(conn, filename, &st,FILE_READ_ATTRIBUTES,0,
1923 (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), &action);
1925 if (!fsp) {
1926 DEBUG(3,("_srv_net_file_query_secdesc: Unable to open file %s\n", filename));
1927 r_u->status = WERR_ACCESS_DENIED;
1928 goto error_exit;
1932 sd_size = SMB_VFS_GET_NT_ACL(fsp, fsp->fsp_name, (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION), &psd);
1934 if (sd_size == 0) {
1935 DEBUG(3,("_srv_net_file_query_secdesc: Unable to get NT ACL for file %s\n", filename));
1936 r_u->status = WERR_ACCESS_DENIED;
1937 goto error_exit;
1940 r_u->ptr_response = 1;
1941 r_u->size_response = sd_size;
1942 r_u->ptr_secdesc = 1;
1943 r_u->size_secdesc = sd_size;
1944 r_u->sec_desc = psd;
1946 psd->dacl->revision = (uint16) NT4_ACL_REVISION;
1948 close_file(fsp, True);
1949 unbecome_user();
1950 close_cnum(conn, user.vuid);
1951 return r_u->status;
1953 error_exit:
1955 if(fsp) {
1956 close_file(fsp, True);
1959 if (became_user)
1960 unbecome_user();
1962 if (conn)
1963 close_cnum(conn, user.vuid);
1965 return r_u->status;
1968 /***********************************************************************************
1969 Win9x NT tools set security descriptor.
1970 ***********************************************************************************/
1972 WERROR _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *q_u,
1973 SRV_R_NET_FILE_SET_SECDESC *r_u)
1975 BOOL ret;
1976 pstring filename;
1977 pstring qualname;
1978 DATA_BLOB null_pw;
1979 files_struct *fsp = NULL;
1980 SMB_STRUCT_STAT st;
1981 BOOL bad_path;
1982 int access_mode;
1983 int action;
1984 NTSTATUS nt_status;
1985 struct current_user user;
1986 connection_struct *conn = NULL;
1987 BOOL became_user = False;
1989 ZERO_STRUCT(st);
1991 r_u->status = WERR_OK;
1993 unistr2_to_ascii(qualname, &q_u->uni_qual_name, sizeof(qualname));
1995 /* Null password is ok - we are already an authenticated user... */
1996 null_pw = data_blob(NULL, 0);
1998 get_current_user(&user, p);
2000 become_root();
2001 conn = make_connection(qualname, null_pw, "A:", user.vuid, &nt_status);
2002 unbecome_root();
2004 if (conn == NULL) {
2005 DEBUG(3,("_srv_net_file_set_secdesc: Unable to connect to %s\n", qualname));
2006 r_u->status = ntstatus_to_werror(nt_status);
2007 goto error_exit;
2010 if (!become_user(conn, conn->vuid)) {
2011 DEBUG(0,("_srv_net_file_set_secdesc: Can't become connected user!\n"));
2012 r_u->status = WERR_ACCESS_DENIED;
2013 goto error_exit;
2015 became_user = True;
2017 unistr2_to_ascii(filename, &q_u->uni_file_name, sizeof(filename));
2018 unix_convert(filename, conn, NULL, &bad_path, &st);
2019 if (bad_path) {
2020 DEBUG(3,("_srv_net_file_set_secdesc: bad pathname %s\n", filename));
2021 r_u->status = WERR_ACCESS_DENIED;
2022 goto error_exit;
2025 if (!check_name(filename,conn)) {
2026 DEBUG(3,("_srv_net_file_set_secdesc: can't access %s\n", filename));
2027 r_u->status = WERR_ACCESS_DENIED;
2028 goto error_exit;
2032 fsp = open_file_shared(conn, filename, &st, SET_DENY_MODE(DENY_NONE)|SET_OPEN_MODE(DOS_OPEN_RDWR),
2033 (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), FILE_ATTRIBUTE_NORMAL, INTERNAL_OPEN_ONLY,
2034 &access_mode, &action);
2036 if (!fsp) {
2037 /* Perhaps it is a directory */
2038 if (errno == EISDIR)
2039 fsp = open_directory(conn, filename, &st,FILE_READ_ATTRIBUTES,0,
2040 (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), &action);
2042 if (!fsp) {
2043 DEBUG(3,("_srv_net_file_set_secdesc: Unable to open file %s\n", filename));
2044 r_u->status = WERR_ACCESS_DENIED;
2045 goto error_exit;
2049 ret = SMB_VFS_SET_NT_ACL(fsp, fsp->fsp_name, q_u->sec_info, q_u->sec_desc);
2051 if (ret == False) {
2052 DEBUG(3,("_srv_net_file_set_secdesc: Unable to set NT ACL on file %s\n", filename));
2053 r_u->status = WERR_ACCESS_DENIED;
2054 goto error_exit;
2057 close_file(fsp, True);
2058 unbecome_user();
2059 close_cnum(conn, user.vuid);
2060 return r_u->status;
2062 error_exit:
2064 if(fsp) {
2065 close_file(fsp, True);
2068 if (became_user)
2069 unbecome_user();
2071 if (conn)
2072 close_cnum(conn, user.vuid);
2074 return r_u->status;
2077 /***********************************************************************************
2078 It may be that we want to limit users to creating shares on certain areas of the UNIX file area.
2079 We could define areas by mapping Windows style disks to points on the UNIX directory hierarchy.
2080 These disks would the disks listed by this function.
2081 Users could then create shares relative to these disks. Watch out for moving these disks around.
2082 "Nigel Williams" <nigel@veritas.com>.
2083 ***********************************************************************************/
2085 static const char *server_disks[] = {"C:"};
2087 static uint32 get_server_disk_count(void)
2089 return sizeof(server_disks)/sizeof(server_disks[0]);
2092 static uint32 init_server_disk_enum(uint32 *resume)
2094 uint32 server_disk_count = get_server_disk_count();
2096 /*resume can be an offset into the list for now*/
2098 if(*resume & 0x80000000)
2099 *resume = 0;
2101 if(*resume > server_disk_count)
2102 *resume = server_disk_count;
2104 return server_disk_count - *resume;
2107 static const char *next_server_disk_enum(uint32 *resume)
2109 const char *disk;
2111 if(init_server_disk_enum(resume) == 0)
2112 return NULL;
2114 disk = server_disks[*resume];
2116 (*resume)++;
2118 DEBUG(10, ("next_server_disk_enum: reporting disk %s. resume handle %d.\n", disk, *resume));
2120 return disk;
2123 WERROR _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET_DISK_ENUM *r_u)
2125 uint32 i;
2126 const char *disk_name;
2127 TALLOC_CTX *ctx = p->mem_ctx;
2128 uint32 resume=get_enum_hnd(&q_u->enum_hnd);
2130 r_u->status=WERR_OK;
2132 r_u->total_entries = init_server_disk_enum(&resume);
2134 r_u->disk_enum_ctr.unknown = 0;
2136 if(!(r_u->disk_enum_ctr.disk_info = TALLOC_ARRAY(ctx, DISK_INFO, MAX_SERVER_DISK_ENTRIES))) {
2137 return WERR_NOMEM;
2140 r_u->disk_enum_ctr.disk_info_ptr = r_u->disk_enum_ctr.disk_info ? 1 : 0;
2142 /*allow one DISK_INFO for null terminator*/
2144 for(i = 0; i < MAX_SERVER_DISK_ENTRIES -1 && (disk_name = next_server_disk_enum(&resume)); i++) {
2146 r_u->disk_enum_ctr.entries_read++;
2148 /*copy disk name into a unicode string*/
2150 init_unistr3(&r_u->disk_enum_ctr.disk_info[i].disk_name, disk_name);
2153 /* add a terminating null string. Is this there if there is more data to come? */
2155 r_u->disk_enum_ctr.entries_read++;
2157 init_unistr3(&r_u->disk_enum_ctr.disk_info[i].disk_name, "");
2159 init_enum_hnd(&r_u->enum_hnd, resume);
2161 return r_u->status;
2164 WERROR _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV_R_NET_NAME_VALIDATE *r_u)
2166 int snum;
2167 fstring share_name;
2169 r_u->status=WERR_OK;
2171 switch(q_u->type) {
2173 case 0x9:
2175 /*check if share name is ok*/
2176 /*also check if we already have a share with this name*/
2178 unistr2_to_ascii(share_name, &q_u->uni_name, sizeof(share_name));
2179 snum = find_service(share_name);
2181 /* Share already exists. */
2182 if (snum >= 0)
2183 r_u->status = WERR_ALREADY_EXISTS;
2184 break;
2186 default:
2187 /*unsupported type*/
2188 r_u->status = WERR_UNKNOWN_LEVEL;
2189 break;
2192 return r_u->status;