f0a105e33e0a481fee925082719fef86ae0c7074
[samba.git] / source3 / rpc_server / srvsvc / srv_srvsvc_nt.c
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  *  Copyright (C) Gerald (Jerry) Carter        2006.
8  *  Copyright (C) Guenther Deschner            2008.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 3 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
22  */
23
24 /* This is the implementation of the srvsvc pipe. */
25
26 #include "includes.h"
27 #include "../librpc/gen_ndr/srv_srvsvc.h"
28 #include "librpc/gen_ndr/messaging.h"
29 #include "../libcli/security/security.h"
30 #include "../librpc/gen_ndr/ndr_security.h"
31 #include "dbwrap.h"
32 #include "session.h"
33
34 extern const struct generic_mapping file_generic_mapping;
35
36 #undef DBGC_CLASS
37 #define DBGC_CLASS DBGC_RPC_SRV
38
39 #define MAX_SERVER_DISK_ENTRIES 15
40
41 /* Use for enumerating connections, pipes, & files */
42
43 struct file_enum_count {
44         TALLOC_CTX *ctx;
45         const char *username;
46         struct srvsvc_NetFileCtr3 *ctr3;
47 };
48
49 struct sess_file_count {
50         struct server_id pid;
51         uid_t uid;
52         int count;
53 };
54
55 /****************************************************************************
56  Count the entries belonging to a service in the connection db.
57 ****************************************************************************/
58
59 static int pipe_enum_fn( struct db_record *rec, void *p)
60 {
61         struct pipe_open_rec prec;
62         struct file_enum_count *fenum = (struct file_enum_count *)p;
63         struct srvsvc_NetFileInfo3 *f;
64         int i = fenum->ctr3->count;
65         char *fullpath = NULL;
66         const char *username;
67
68         if (rec->value.dsize != sizeof(struct pipe_open_rec))
69                 return 0;
70
71         memcpy(&prec, rec->value.dptr, sizeof(struct pipe_open_rec));
72
73         if ( !process_exists(prec.pid) ) {
74                 return 0;
75         }
76
77         username = uidtoname(prec.uid);
78
79         if ((fenum->username != NULL)
80             && !strequal(username, fenum->username)) {
81                 return 0;
82         }
83
84         fullpath = talloc_asprintf(fenum->ctx, "\\PIPE\\%s", prec.name );
85         if (!fullpath) {
86                 return 1;
87         }
88
89         f = TALLOC_REALLOC_ARRAY(fenum->ctx, fenum->ctr3->array,
90                                  struct srvsvc_NetFileInfo3, i+1);
91         if ( !f ) {
92                 DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1));
93                 return 1;
94         }
95         fenum->ctr3->array = f;
96
97         fenum->ctr3->array[i].fid               =
98                 (((uint32_t)(procid_to_pid(&prec.pid))<<16) | prec.pnum);
99         fenum->ctr3->array[i].permissions       =
100                 (FILE_READ_DATA|FILE_WRITE_DATA);
101         fenum->ctr3->array[i].num_locks         = 0;
102         fenum->ctr3->array[i].path              = fullpath;
103         fenum->ctr3->array[i].user              = username;
104
105         fenum->ctr3->count++;
106
107         return 0;
108 }
109
110 /*******************************************************************
111 ********************************************************************/
112
113 static WERROR net_enum_pipes(TALLOC_CTX *ctx,
114                              const char *username,
115                              struct srvsvc_NetFileCtr3 **ctr3,
116                              uint32_t resume )
117 {
118         struct file_enum_count fenum;
119
120         fenum.ctx = ctx;
121         fenum.username = username;
122         fenum.ctr3 = *ctr3;
123
124         if (connections_traverse(pipe_enum_fn, &fenum) == -1) {
125                 DEBUG(0,("net_enum_pipes: traverse of connections.tdb "
126                          "failed\n"));
127                 return WERR_NOMEM;
128         }
129
130         *ctr3 = fenum.ctr3;
131
132         return WERR_OK;
133 }
134
135 /*******************************************************************
136 ********************************************************************/
137
138 static void enum_file_fn( const struct share_mode_entry *e,
139                           const char *sharepath, const char *fname,
140                           void *private_data )
141 {
142         struct file_enum_count *fenum =
143                 (struct file_enum_count *)private_data;
144
145         struct srvsvc_NetFileInfo3 *f;
146         int i = fenum->ctr3->count;
147         files_struct fsp;
148         struct byte_range_lock *brl;
149         int num_locks = 0;
150         char *fullpath = NULL;
151         uint32 permissions;
152         const char *username;
153
154         /* If the pid was not found delete the entry from connections.tdb */
155
156         if ( !process_exists(e->pid) ) {
157                 return;
158         }
159
160         username = uidtoname(e->uid);
161
162         if ((fenum->username != NULL)
163             && !strequal(username, fenum->username)) {
164                 return;
165         }
166
167         f = TALLOC_REALLOC_ARRAY(fenum->ctx, fenum->ctr3->array,
168                                  struct srvsvc_NetFileInfo3, i+1);
169         if ( !f ) {
170                 DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1));
171                 return;
172         }
173         fenum->ctr3->array = f;
174
175         /* need to count the number of locks on a file */
176
177         ZERO_STRUCT( fsp );
178         fsp.file_id = e->id;
179
180         if ( (brl = brl_get_locks(talloc_tos(), &fsp)) != NULL ) {
181                 num_locks = brl->num_locks;
182                 TALLOC_FREE(brl);
183         }
184
185         if ( strcmp( fname, "." ) == 0 ) {
186                 fullpath = talloc_asprintf(fenum->ctx, "C:%s", sharepath );
187         } else {
188                 fullpath = talloc_asprintf(fenum->ctx, "C:%s/%s",
189                                 sharepath, fname );
190         }
191         if (!fullpath) {
192                 return;
193         }
194         string_replace( fullpath, '/', '\\' );
195
196         /* mask out create (what ever that is) */
197         permissions = e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA);
198
199         /* now fill in the srvsvc_NetFileInfo3 struct */
200
201         fenum->ctr3->array[i].fid               =
202                 (((uint32_t)(procid_to_pid(&e->pid))<<16) | e->share_file_id);
203         fenum->ctr3->array[i].permissions       = permissions;
204         fenum->ctr3->array[i].num_locks         = num_locks;
205         fenum->ctr3->array[i].path              = fullpath;
206         fenum->ctr3->array[i].user              = username;
207
208         fenum->ctr3->count++;
209 }
210
211 /*******************************************************************
212 ********************************************************************/
213
214 static WERROR net_enum_files(TALLOC_CTX *ctx,
215                              const char *username,
216                              struct srvsvc_NetFileCtr3 **ctr3,
217                              uint32_t resume)
218 {
219         struct file_enum_count f_enum_cnt;
220
221         f_enum_cnt.ctx = ctx;
222         f_enum_cnt.username = username;
223         f_enum_cnt.ctr3 = *ctr3;
224
225         share_mode_forall( enum_file_fn, (void *)&f_enum_cnt );
226
227         *ctr3 = f_enum_cnt.ctr3;
228
229         return WERR_OK;
230 }
231
232 /*******************************************************************
233  Utility function to get the 'type' of a share from an snum.
234  ********************************************************************/
235 static uint32 get_share_type(int snum)
236 {
237         /* work out the share type */
238         uint32 type = STYPE_DISKTREE;
239
240         if (lp_print_ok(snum))
241                 type = STYPE_PRINTQ;
242         if (strequal(lp_fstype(snum), "IPC"))
243                 type = STYPE_IPC;
244         if (lp_administrative_share(snum))
245                 type |= STYPE_HIDDEN;
246
247         return type;
248 }
249
250 /*******************************************************************
251  Fill in a share info level 0 structure.
252  ********************************************************************/
253
254 static void init_srv_share_info_0(struct pipes_struct *p,
255                                   struct srvsvc_NetShareInfo0 *r, int snum)
256 {
257         r->name         = lp_servicename(snum);
258 }
259
260 /*******************************************************************
261  Fill in a share info level 1 structure.
262  ********************************************************************/
263
264 static void init_srv_share_info_1(struct pipes_struct *p,
265                                   struct srvsvc_NetShareInfo1 *r,
266                                   int snum)
267 {
268         char *net_name = lp_servicename(snum);
269         char *remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
270
271         if (remark) {
272                 remark = talloc_sub_advanced(
273                         p->mem_ctx, lp_servicename(snum),
274                         get_current_username(), lp_pathname(snum),
275                         p->session_info->utok.uid, get_current_username(),
276                         "", remark);
277         }
278
279         r->name         = net_name;
280         r->type         = get_share_type(snum);
281         r->comment      = remark ? remark : "";
282 }
283
284 /*******************************************************************
285  Fill in a share info level 2 structure.
286  ********************************************************************/
287
288 static void init_srv_share_info_2(struct pipes_struct *p,
289                                   struct srvsvc_NetShareInfo2 *r,
290                                   int snum)
291 {
292         char *remark = NULL;
293         char *path = NULL;
294         int max_connections = lp_max_connections(snum);
295         uint32_t max_uses = max_connections!=0 ? max_connections : (uint32_t)-1;
296         char *net_name = lp_servicename(snum);
297
298         remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
299         if (remark) {
300                 remark = talloc_sub_advanced(
301                         p->mem_ctx, lp_servicename(snum),
302                         get_current_username(), lp_pathname(snum),
303                         p->session_info->utok.uid, get_current_username(),
304                         "", remark);
305         }
306         path = talloc_asprintf(p->mem_ctx,
307                         "C:%s", lp_pathname(snum));
308
309         if (path) {
310                 /*
311                  * Change / to \\ so that win2k will see it as a valid path.
312                  * This was added to enable use of browsing in win2k add
313                  * share dialog.
314                  */
315
316                 string_replace(path, '/', '\\');
317         }
318
319         r->name                 = net_name;
320         r->type                 = get_share_type(snum);
321         r->comment              = remark ? remark : "";
322         r->permissions          = 0;
323         r->max_users            = max_uses;
324         r->current_users        = count_current_connections(net_name, false);
325         r->path                 = path ? path : "";
326         r->password             = "";
327 }
328
329 /*******************************************************************
330  Map any generic bits to file specific bits.
331 ********************************************************************/
332
333 static void map_generic_share_sd_bits(struct security_descriptor *psd)
334 {
335         int i;
336         struct security_acl *ps_dacl = NULL;
337
338         if (!psd)
339                 return;
340
341         ps_dacl = psd->dacl;
342         if (!ps_dacl)
343                 return;
344
345         for (i = 0; i < ps_dacl->num_aces; i++) {
346                 struct security_ace *psa = &ps_dacl->aces[i];
347                 uint32 orig_mask = psa->access_mask;
348
349                 se_map_generic(&psa->access_mask, &file_generic_mapping);
350                 psa->access_mask |= orig_mask;
351         }
352 }
353
354 /*******************************************************************
355  Fill in a share info level 501 structure.
356 ********************************************************************/
357
358 static void init_srv_share_info_501(struct pipes_struct *p,
359                                     struct srvsvc_NetShareInfo501 *r, int snum)
360 {
361         const char *net_name = lp_servicename(snum);
362         char *remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
363
364         if (remark) {
365                 remark = talloc_sub_advanced(
366                         p->mem_ctx, lp_servicename(snum),
367                         get_current_username(), lp_pathname(snum),
368                         p->session_info->utok.uid, get_current_username(),
369                         "", remark);
370         }
371
372         r->name         = net_name;
373         r->type         = get_share_type(snum);
374         r->comment      = remark ? remark : "";
375         r->csc_policy   = (lp_csc_policy(snum) << 4);
376 }
377
378 /*******************************************************************
379  Fill in a share info level 502 structure.
380  ********************************************************************/
381
382 static void init_srv_share_info_502(struct pipes_struct *p,
383                                     struct srvsvc_NetShareInfo502 *r, int snum)
384 {
385         const char *net_name = lp_servicename(snum);
386         char *path = NULL;
387         struct security_descriptor *sd = NULL;
388         struct sec_desc_buf *sd_buf = NULL;
389         size_t sd_size = 0;
390         TALLOC_CTX *ctx = p->mem_ctx;
391         char *remark = talloc_strdup(ctx, lp_comment(snum));
392
393         if (remark) {
394                 remark = talloc_sub_advanced(
395                         p->mem_ctx, lp_servicename(snum),
396                         get_current_username(), lp_pathname(snum),
397                         p->session_info->utok.uid, get_current_username(),
398                         "", remark);
399         }
400         path = talloc_asprintf(ctx, "C:%s", lp_pathname(snum));
401         if (path) {
402                 /*
403                  * Change / to \\ so that win2k will see it as a valid path.  This was added to
404                  * enable use of browsing in win2k add share dialog.
405                  */
406                 string_replace(path, '/', '\\');
407         }
408
409         sd = get_share_security(ctx, lp_servicename(snum), &sd_size);
410
411         sd_buf = make_sec_desc_buf(p->mem_ctx, sd_size, sd);
412
413         r->name                 = net_name;
414         r->type                 = get_share_type(snum);
415         r->comment              = remark ? remark : "";
416         r->permissions          = 0;
417         r->max_users            = (uint32_t)-1;
418         r->current_users        = 1; /* ??? */
419         r->path                 = path ? path : "";
420         r->password             = "";
421         r->sd_buf               = *sd_buf;
422 }
423
424 /***************************************************************************
425  Fill in a share info level 1004 structure.
426  ***************************************************************************/
427
428 static void init_srv_share_info_1004(struct pipes_struct *p,
429                                      struct srvsvc_NetShareInfo1004 *r,
430                                      int snum)
431 {
432         char *remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
433
434         if (remark) {
435                 remark = talloc_sub_advanced(
436                         p->mem_ctx, lp_servicename(snum),
437                         get_current_username(), lp_pathname(snum),
438                         p->session_info->utok.uid, get_current_username(),
439                         "", remark);
440         }
441
442         r->comment      = remark ? remark : "";
443 }
444
445 /***************************************************************************
446  Fill in a share info level 1005 structure.
447  ***************************************************************************/
448
449 static void init_srv_share_info_1005(struct pipes_struct *p,
450                                      struct srvsvc_NetShareInfo1005 *r,
451                                      int snum)
452 {
453         uint32_t dfs_flags = 0;
454
455         if (lp_host_msdfs() && lp_msdfs_root(snum)) {
456                 dfs_flags |= SHARE_1005_IN_DFS | SHARE_1005_DFS_ROOT;
457         }
458
459         dfs_flags |= lp_csc_policy(snum) << SHARE_1005_CSC_POLICY_SHIFT;
460
461         r->dfs_flags    = dfs_flags;
462 }
463
464 /***************************************************************************
465  Fill in a share info level 1006 structure.
466  ***************************************************************************/
467
468 static void init_srv_share_info_1006(struct pipes_struct *p,
469                                      struct srvsvc_NetShareInfo1006 *r,
470                                      int snum)
471 {
472         r->max_users    = (uint32_t)-1;
473 }
474
475 /***************************************************************************
476  Fill in a share info level 1007 structure.
477  ***************************************************************************/
478
479 static void init_srv_share_info_1007(struct pipes_struct *p,
480                                      struct srvsvc_NetShareInfo1007 *r,
481                                      int snum)
482 {
483         r->flags                        = 0;
484         r->alternate_directory_name     = "";
485 }
486
487 /*******************************************************************
488  Fill in a share info level 1501 structure.
489  ********************************************************************/
490
491 static void init_srv_share_info_1501(struct pipes_struct *p,
492                                      struct sec_desc_buf *r,
493                                      int snum)
494 {
495         struct security_descriptor *sd;
496         size_t sd_size;
497         TALLOC_CTX *ctx = p->mem_ctx;
498
499         sd = get_share_security(ctx, lp_servicename(snum), &sd_size);
500
501         r = make_sec_desc_buf(p->mem_ctx, sd_size, sd);
502 }
503
504 /*******************************************************************
505  True if it ends in '$'.
506  ********************************************************************/
507
508 static bool is_hidden_share(int snum)
509 {
510         const char *net_name = lp_servicename(snum);
511
512         return (net_name[strlen(net_name) - 1] == '$') ? True : False;
513 }
514
515 /*******************************************************************
516  Verify user is allowed to view share, access based enumeration
517 ********************************************************************/
518 static bool is_enumeration_allowed(struct pipes_struct *p,
519                                    int snum)
520 {
521     if (!lp_access_based_share_enum(snum))
522         return true;
523
524     return share_access_check(p->session_info->security_token, lp_servicename(snum),
525                               FILE_READ_DATA);
526 }
527
528 /*******************************************************************
529  Fill in a share info structure.
530  ********************************************************************/
531
532 static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
533                                       struct srvsvc_NetShareInfoCtr *info_ctr,
534                                       uint32_t *resume_handle_p,
535                                       uint32_t *total_entries,
536                                       bool all_shares)
537 {
538         int num_entries = 0;
539         int alloc_entries = 0;
540         int num_services = 0;
541         int snum;
542         TALLOC_CTX *ctx = p->mem_ctx;
543         int i = 0;
544         int valid_share_count = 0;
545         bool *allowed = 0;
546         union srvsvc_NetShareCtr ctr;
547         uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
548
549         DEBUG(5,("init_srv_share_info_ctr\n"));
550
551         /* Ensure all the usershares are loaded. */
552         become_root();
553         load_usershare_shares();
554         load_registry_shares();
555         num_services = lp_numservices();
556         unbecome_root();
557
558         allowed = TALLOC_ZERO_ARRAY(ctx, bool, num_services);
559         W_ERROR_HAVE_NO_MEMORY(allowed);
560
561         /* Count the number of entries. */
562         for (snum = 0; snum < num_services; snum++) {
563                 if (lp_browseable(snum) && lp_snum_ok(snum) &&
564                     is_enumeration_allowed(p, snum) &&
565                     (all_shares || !is_hidden_share(snum)) ) {
566                         DEBUG(10, ("counting service %s\n",
567                                 lp_servicename(snum) ? lp_servicename(snum) : "(null)"));
568                         allowed[snum] = true;
569                         num_entries++;
570                 } else {
571                         DEBUG(10, ("NOT counting service %s\n",
572                                 lp_servicename(snum) ? lp_servicename(snum) : "(null)"));
573                 }
574         }
575
576         if (!num_entries || (resume_handle >= num_entries)) {
577                 return WERR_OK;
578         }
579
580         /* Calculate alloc entries. */
581         alloc_entries = num_entries - resume_handle;
582         switch (info_ctr->level) {
583         case 0:
584                 ctr.ctr0 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr0);
585                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr0);
586
587                 ctr.ctr0->count = alloc_entries;
588                 ctr.ctr0->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo0, alloc_entries);
589                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr0->array);
590
591                 for (snum = 0; snum < num_services; snum++) {
592                         if (allowed[snum] &&
593                             (resume_handle <= (i + valid_share_count++)) ) {
594                                 init_srv_share_info_0(p, &ctr.ctr0->array[i++], snum);
595                         }
596                 }
597
598                 break;
599
600         case 1:
601                 ctr.ctr1 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr1);
602                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1);
603
604                 ctr.ctr1->count = alloc_entries;
605                 ctr.ctr1->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo1, alloc_entries);
606                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1->array);
607
608                 for (snum = 0; snum < num_services; snum++) {
609                         if (allowed[snum] &&
610                             (resume_handle <= (i + valid_share_count++)) ) {
611                                 init_srv_share_info_1(p, &ctr.ctr1->array[i++], snum);
612                         }
613                 }
614
615                 break;
616
617         case 2:
618                 ctr.ctr2 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr2);
619                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr2);
620
621                 ctr.ctr2->count = alloc_entries;
622                 ctr.ctr2->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo2, alloc_entries);
623                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr2->array);
624
625                 for (snum = 0; snum < num_services; snum++) {
626                         if (allowed[snum] &&
627                             (resume_handle <= (i + valid_share_count++)) ) {
628                                 init_srv_share_info_2(p, &ctr.ctr2->array[i++], snum);
629                         }
630                 }
631
632                 break;
633
634         case 501:
635                 ctr.ctr501 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr501);
636                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr501);
637
638                 ctr.ctr501->count = alloc_entries;
639                 ctr.ctr501->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo501, alloc_entries);
640                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr501->array);
641
642                 for (snum = 0; snum < num_services; snum++) {
643                         if (allowed[snum] &&
644                             (resume_handle <= (i + valid_share_count++)) ) {
645                                 init_srv_share_info_501(p, &ctr.ctr501->array[i++], snum);
646                         }
647                 }
648
649                 break;
650
651         case 502:
652                 ctr.ctr502 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr502);
653                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr502);
654
655                 ctr.ctr502->count = alloc_entries;
656                 ctr.ctr502->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo502, alloc_entries);
657                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr502->array);
658
659                 for (snum = 0; snum < num_services; snum++) {
660                         if (allowed[snum] &&
661                             (resume_handle <= (i + valid_share_count++)) ) {
662                                 init_srv_share_info_502(p, &ctr.ctr502->array[i++], snum);
663                         }
664                 }
665
666                 break;
667
668         case 1004:
669                 ctr.ctr1004 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr1004);
670                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1004);
671
672                 ctr.ctr1004->count = alloc_entries;
673                 ctr.ctr1004->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo1004, alloc_entries);
674                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1004->array);
675
676                 for (snum = 0; snum < num_services; snum++) {
677                         if (allowed[snum] &&
678                             (resume_handle <= (i + valid_share_count++)) ) {
679                                 init_srv_share_info_1004(p, &ctr.ctr1004->array[i++], snum);
680                         }
681                 }
682
683                 break;
684
685         case 1005:
686                 ctr.ctr1005 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr1005);
687                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1005);
688
689                 ctr.ctr1005->count = alloc_entries;
690                 ctr.ctr1005->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo1005, alloc_entries);
691                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1005->array);
692
693                 for (snum = 0; snum < num_services; snum++) {
694                         if (allowed[snum] &&
695                             (resume_handle <= (i + valid_share_count++)) ) {
696                                 init_srv_share_info_1005(p, &ctr.ctr1005->array[i++], snum);
697                         }
698                 }
699
700                 break;
701
702         case 1006:
703                 ctr.ctr1006 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr1006);
704                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1006);
705
706                 ctr.ctr1006->count = alloc_entries;
707                 ctr.ctr1006->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo1006, alloc_entries);
708                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1006->array);
709
710                 for (snum = 0; snum < num_services; snum++) {
711                         if (allowed[snum] &&
712                             (resume_handle <= (i + valid_share_count++)) ) {
713                                 init_srv_share_info_1006(p, &ctr.ctr1006->array[i++], snum);
714                         }
715                 }
716
717                 break;
718
719         case 1007:
720                 ctr.ctr1007 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr1007);
721                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1007);
722
723                 ctr.ctr1007->count = alloc_entries;
724                 ctr.ctr1007->array = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetShareInfo1007, alloc_entries);
725                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1007->array);
726
727                 for (snum = 0; snum < num_services; snum++) {
728                         if (allowed[snum] &&
729                             (resume_handle <= (i + valid_share_count++)) ) {
730                                 init_srv_share_info_1007(p, &ctr.ctr1007->array[i++], snum);
731                         }
732                 }
733
734                 break;
735
736         case 1501:
737                 ctr.ctr1501 = TALLOC_ZERO_P(ctx, struct srvsvc_NetShareCtr1501);
738                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1501);
739
740                 ctr.ctr1501->count = alloc_entries;
741                 ctr.ctr1501->array = TALLOC_ZERO_ARRAY(ctx, struct sec_desc_buf, alloc_entries);
742                 W_ERROR_HAVE_NO_MEMORY(ctr.ctr1501->array);
743
744                 for (snum = 0; snum < num_services; snum++) {
745                         if (allowed[snum] &&
746                             (resume_handle <= (i + valid_share_count++)) ) {
747                                 init_srv_share_info_1501(p, &ctr.ctr1501->array[i++], snum);
748                         }
749                 }
750
751                 break;
752
753         default:
754                 DEBUG(5,("init_srv_share_info_ctr: unsupported switch value %d\n",
755                         info_ctr->level));
756                 return WERR_UNKNOWN_LEVEL;
757         }
758
759         *total_entries = alloc_entries;
760         if (resume_handle_p) {
761                 if (all_shares) {
762                         *resume_handle_p = (num_entries == 0) ? *resume_handle_p : 0;
763                 } else {
764                         *resume_handle_p = num_entries;
765                 }
766         }
767
768         info_ctr->ctr = ctr;
769
770         return WERR_OK;
771 }
772
773 /*******************************************************************
774  fill in a sess info level 0 structure.
775  ********************************************************************/
776
777 static WERROR init_srv_sess_info_0(struct pipes_struct *p,
778                                    struct srvsvc_NetSessCtr0 *ctr0,
779                                    uint32_t *resume_handle_p,
780                                    uint32_t *total_entries)
781 {
782         struct sessionid *session_list;
783         uint32_t num_entries = 0;
784         uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
785         *total_entries = list_sessions(p->mem_ctx, &session_list);
786
787         DEBUG(5,("init_srv_sess_info_0\n"));
788
789         if (ctr0 == NULL) {
790                 if (resume_handle_p) {
791                         *resume_handle_p = 0;
792                 }
793                 return WERR_OK;
794         }
795
796         for (; resume_handle < *total_entries; resume_handle++) {
797
798                 ctr0->array = TALLOC_REALLOC_ARRAY(p->mem_ctx,
799                                                    ctr0->array,
800                                                    struct srvsvc_NetSessInfo0,
801                                                    num_entries+1);
802                 W_ERROR_HAVE_NO_MEMORY(ctr0->array);
803
804                 ctr0->array[num_entries].client =
805                         session_list[resume_handle].remote_machine;
806
807                 num_entries++;
808         }
809
810         ctr0->count = num_entries;
811
812         if (resume_handle_p) {
813                 if (*resume_handle_p >= *total_entries) {
814                         *resume_handle_p = 0;
815                 } else {
816                         *resume_handle_p = resume_handle;
817                 }
818         }
819
820         return WERR_OK;
821 }
822
823 /*******************************************************************
824 ********************************************************************/
825
826 static void sess_file_fn( const struct share_mode_entry *e,
827                           const char *sharepath, const char *fname,
828                           void *data )
829 {
830         struct sess_file_count *sess = (struct sess_file_count *)data;
831
832         if ( procid_equal(&e->pid, &sess->pid) && (sess->uid == e->uid) ) {
833                 sess->count++;
834         }
835
836         return;
837 }
838
839 /*******************************************************************
840 ********************************************************************/
841
842 static int net_count_files( uid_t uid, struct server_id pid )
843 {
844         struct sess_file_count s_file_cnt;
845
846         s_file_cnt.count = 0;
847         s_file_cnt.uid = uid;
848         s_file_cnt.pid = pid;
849
850         share_mode_forall( sess_file_fn, &s_file_cnt );
851
852         return s_file_cnt.count;
853 }
854
855 /*******************************************************************
856  fill in a sess info level 1 structure.
857  ********************************************************************/
858
859 static WERROR init_srv_sess_info_1(struct pipes_struct *p,
860                                    struct srvsvc_NetSessCtr1 *ctr1,
861                                    uint32_t *resume_handle_p,
862                                    uint32_t *total_entries)
863 {
864         struct sessionid *session_list;
865         uint32_t num_entries = 0;
866         time_t now = time(NULL);
867         uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
868
869         ZERO_STRUCTP(ctr1);
870
871         if (ctr1 == NULL) {
872                 if (resume_handle_p) {
873                         *resume_handle_p = 0;
874                 }
875                 return WERR_OK;
876         }
877
878         *total_entries = list_sessions(p->mem_ctx, &session_list);
879
880         for (; resume_handle < *total_entries; resume_handle++) {
881                 uint32 num_files;
882                 uint32 connect_time;
883                 struct passwd *pw = sys_getpwnam(session_list[resume_handle].username);
884                 bool guest;
885
886                 if ( !pw ) {
887                         DEBUG(10,("init_srv_sess_info_1: failed to find owner: %s\n",
888                                 session_list[resume_handle].username));
889                         continue;
890                 }
891
892                 connect_time = (uint32_t)(now - session_list[resume_handle].connect_start);
893                 num_files = net_count_files(pw->pw_uid, session_list[resume_handle].pid);
894                 guest = strequal( session_list[resume_handle].username, lp_guestaccount() );
895
896                 ctr1->array = TALLOC_REALLOC_ARRAY(p->mem_ctx,
897                                                    ctr1->array,
898                                                    struct srvsvc_NetSessInfo1,
899                                                    num_entries+1);
900                 W_ERROR_HAVE_NO_MEMORY(ctr1->array);
901
902                 ctr1->array[num_entries].client         = session_list[resume_handle].remote_machine;
903                 ctr1->array[num_entries].user           = session_list[resume_handle].username;
904                 ctr1->array[num_entries].num_open       = num_files;
905                 ctr1->array[num_entries].time           = connect_time;
906                 ctr1->array[num_entries].idle_time      = 0;
907                 ctr1->array[num_entries].user_flags     = guest;
908
909                 num_entries++;
910         }
911
912         ctr1->count = num_entries;
913
914         if (resume_handle_p) {
915                 if (*resume_handle_p >= *total_entries) {
916                         *resume_handle_p = 0;
917                 } else {
918                         *resume_handle_p = resume_handle;
919                 }
920         }
921
922         return WERR_OK;
923 }
924
925 /*******************************************************************
926  fill in a conn info level 0 structure.
927  ********************************************************************/
928
929 static WERROR init_srv_conn_info_0(struct srvsvc_NetConnCtr0 *ctr0,
930                                    uint32_t *resume_handle_p,
931                                    uint32_t *total_entries)
932 {
933         uint32_t num_entries = 0;
934         uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
935
936         DEBUG(5,("init_srv_conn_info_0\n"));
937
938         if (ctr0 == NULL) {
939                 if (resume_handle_p) {
940                         *resume_handle_p = 0;
941                 }
942                 return WERR_OK;
943         }
944
945         *total_entries = 1;
946
947         ZERO_STRUCTP(ctr0);
948
949         for (; resume_handle < *total_entries; resume_handle++) {
950
951                 ctr0->array = TALLOC_REALLOC_ARRAY(talloc_tos(),
952                                                    ctr0->array,
953                                                    struct srvsvc_NetConnInfo0,
954                                                    num_entries+1);
955                 if (!ctr0->array) {
956                         return WERR_NOMEM;
957                 }
958
959                 ctr0->array[num_entries].conn_id = *total_entries;
960
961                 /* move on to creating next connection */
962                 num_entries++;
963         }
964
965         ctr0->count = num_entries;
966         *total_entries = num_entries;
967
968         if (resume_handle_p) {
969                 if (*resume_handle_p >= *total_entries) {
970                         *resume_handle_p = 0;
971                 } else {
972                         *resume_handle_p = resume_handle;
973                 }
974         }
975
976         return WERR_OK;
977 }
978
979 /*******************************************************************
980  fill in a conn info level 1 structure.
981  ********************************************************************/
982
983 static WERROR init_srv_conn_info_1(struct srvsvc_NetConnCtr1 *ctr1,
984                                    uint32_t *resume_handle_p,
985                                    uint32_t *total_entries)
986 {
987         uint32_t num_entries = 0;
988         uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
989
990         DEBUG(5,("init_srv_conn_info_1\n"));
991
992         if (ctr1 == NULL) {
993                 if (resume_handle_p) {
994                         *resume_handle_p = 0;
995                 }
996                 return WERR_OK;
997         }
998
999         *total_entries = 1;
1000
1001         ZERO_STRUCTP(ctr1);
1002
1003         for (; resume_handle < *total_entries; resume_handle++) {
1004
1005                 ctr1->array = TALLOC_REALLOC_ARRAY(talloc_tos(),
1006                                                    ctr1->array,
1007                                                    struct srvsvc_NetConnInfo1,
1008                                                    num_entries+1);
1009                 if (!ctr1->array) {
1010                         return WERR_NOMEM;
1011                 }
1012
1013                 ctr1->array[num_entries].conn_id        = *total_entries;
1014                 ctr1->array[num_entries].conn_type      = 0x3;
1015                 ctr1->array[num_entries].num_open       = 1;
1016                 ctr1->array[num_entries].num_users      = 1;
1017                 ctr1->array[num_entries].conn_time      = 3;
1018                 ctr1->array[num_entries].user           = "dummy_user";
1019                 ctr1->array[num_entries].share          = "IPC$";
1020
1021                 /* move on to creating next connection */
1022                 num_entries++;
1023         }
1024
1025         ctr1->count = num_entries;
1026         *total_entries = num_entries;
1027
1028         if (resume_handle_p) {
1029                 if (*resume_handle_p >= *total_entries) {
1030                         *resume_handle_p = 0;
1031                 } else {
1032                         *resume_handle_p = resume_handle;
1033                 }
1034         }
1035
1036         return WERR_OK;
1037 }
1038
1039 /*******************************************************************
1040  _srvsvc_NetFileEnum
1041 *******************************************************************/
1042
1043 WERROR _srvsvc_NetFileEnum(struct pipes_struct *p,
1044                            struct srvsvc_NetFileEnum *r)
1045 {
1046         TALLOC_CTX *ctx = NULL;
1047         struct srvsvc_NetFileCtr3 *ctr3;
1048         uint32_t resume_hnd = 0;
1049         WERROR werr;
1050
1051         switch (r->in.info_ctr->level) {
1052         case 3:
1053                 break;
1054         default:
1055                 return WERR_UNKNOWN_LEVEL;
1056         }
1057
1058         if (!nt_token_check_sid(&global_sid_Builtin_Administrators,
1059                                 p->session_info->security_token)) {
1060                 DEBUG(1, ("Enumerating files only allowed for "
1061                           "administrators\n"));
1062                 return WERR_ACCESS_DENIED;
1063         }
1064
1065         ctx = talloc_tos();
1066         ctr3 = r->in.info_ctr->ctr.ctr3;
1067         if (!ctr3) {
1068                 werr = WERR_INVALID_PARAM;
1069                 goto done;
1070         }
1071
1072         /* TODO -- Windows enumerates
1073            (b) active pipes
1074            (c) open directories and files */
1075
1076         werr = net_enum_files(ctx, r->in.user, &ctr3, resume_hnd);
1077         if (!W_ERROR_IS_OK(werr)) {
1078                 goto done;
1079         }
1080
1081         werr = net_enum_pipes(ctx, r->in.user, &ctr3, resume_hnd);
1082         if (!W_ERROR_IS_OK(werr)) {
1083                 goto done;
1084         }
1085
1086         *r->out.totalentries = ctr3->count;
1087         r->out.info_ctr->ctr.ctr3->array = ctr3->array;
1088         r->out.info_ctr->ctr.ctr3->count = ctr3->count;
1089
1090         werr = WERR_OK;
1091
1092  done:
1093         return werr;
1094 }
1095
1096 /*******************************************************************
1097  _srvsvc_NetSrvGetInfo
1098 ********************************************************************/
1099
1100 WERROR _srvsvc_NetSrvGetInfo(struct pipes_struct *p,
1101                              struct srvsvc_NetSrvGetInfo *r)
1102 {
1103         WERROR status = WERR_OK;
1104
1105         DEBUG(5,("_srvsvc_NetSrvGetInfo: %d\n", __LINE__));
1106
1107         if (!pipe_access_check(p)) {
1108                 DEBUG(3, ("access denied to _srvsvc_NetSrvGetInfo\n"));
1109                 return WERR_ACCESS_DENIED;
1110         }
1111
1112         switch (r->in.level) {
1113
1114                 /* Technically level 102 should only be available to
1115                    Administrators but there isn't anything super-secret
1116                    here, as most of it is made up. */
1117
1118         case 102: {
1119                 struct srvsvc_NetSrvInfo102 *info102;
1120
1121                 info102 = TALLOC_P(p->mem_ctx, struct srvsvc_NetSrvInfo102);
1122                 if (!info102) {
1123                         return WERR_NOMEM;
1124                 }
1125
1126                 info102->platform_id    = PLATFORM_ID_NT;
1127                 info102->server_name    = global_myname();
1128                 info102->version_major  = lp_major_announce_version();
1129                 info102->version_minor  = lp_minor_announce_version();
1130                 info102->server_type    = lp_default_server_announce();
1131                 info102->comment        = string_truncate(lp_serverstring(),
1132                                                 MAX_SERVER_STRING_LENGTH);
1133                 info102->users          = 0xffffffff;
1134                 info102->disc           = 0xf;
1135                 info102->hidden         = 0;
1136                 info102->announce       = 240;
1137                 info102->anndelta       = 3000;
1138                 info102->licenses       = 100000;
1139                 info102->userpath       = "C:\\";
1140
1141                 r->out.info->info102 = info102;
1142                 break;
1143         }
1144         case 101: {
1145                 struct srvsvc_NetSrvInfo101 *info101;
1146
1147                 info101 = TALLOC_P(p->mem_ctx, struct srvsvc_NetSrvInfo101);
1148                 if (!info101) {
1149                         return WERR_NOMEM;
1150                 }
1151
1152                 info101->platform_id    = PLATFORM_ID_NT;
1153                 info101->server_name    = global_myname();
1154                 info101->version_major  = lp_major_announce_version();
1155                 info101->version_minor  = lp_minor_announce_version();
1156                 info101->server_type    = lp_default_server_announce();
1157                 info101->comment        = string_truncate(lp_serverstring(),
1158                                                 MAX_SERVER_STRING_LENGTH);
1159
1160                 r->out.info->info101 = info101;
1161                 break;
1162         }
1163         case 100: {
1164                 struct srvsvc_NetSrvInfo100 *info100;
1165
1166                 info100 = TALLOC_P(p->mem_ctx, struct srvsvc_NetSrvInfo100);
1167                 if (!info100) {
1168                         return WERR_NOMEM;
1169                 }
1170
1171                 info100->platform_id    = PLATFORM_ID_NT;
1172                 info100->server_name    = global_myname();
1173
1174                 r->out.info->info100 = info100;
1175
1176                 break;
1177         }
1178         default:
1179                 status = WERR_UNKNOWN_LEVEL;
1180                 break;
1181         }
1182
1183         DEBUG(5,("_srvsvc_NetSrvGetInfo: %d\n", __LINE__));
1184
1185         return status;
1186 }
1187
1188 /*******************************************************************
1189  _srvsvc_NetSrvSetInfo
1190 ********************************************************************/
1191
1192 WERROR _srvsvc_NetSrvSetInfo(struct pipes_struct *p,
1193                              struct srvsvc_NetSrvSetInfo *r)
1194 {
1195         WERROR status = WERR_OK;
1196
1197         DEBUG(5,("_srvsvc_NetSrvSetInfo: %d\n", __LINE__));
1198
1199         /* Set up the net server set info structure. */
1200
1201         DEBUG(5,("_srvsvc_NetSrvSetInfo: %d\n", __LINE__));
1202
1203         return status;
1204 }
1205
1206 /*******************************************************************
1207  _srvsvc_NetConnEnum
1208 ********************************************************************/
1209
1210 WERROR _srvsvc_NetConnEnum(struct pipes_struct *p,
1211                            struct srvsvc_NetConnEnum *r)
1212 {
1213         WERROR werr;
1214
1215         DEBUG(5,("_srvsvc_NetConnEnum: %d\n", __LINE__));
1216
1217         if (!nt_token_check_sid(&global_sid_Builtin_Administrators,
1218                                 p->session_info->security_token)) {
1219                 DEBUG(1, ("Enumerating connections only allowed for "
1220                           "administrators\n"));
1221                 return WERR_ACCESS_DENIED;
1222         }
1223
1224         switch (r->in.info_ctr->level) {
1225                 case 0:
1226                         werr = init_srv_conn_info_0(r->in.info_ctr->ctr.ctr0,
1227                                                     r->in.resume_handle,
1228                                                     r->out.totalentries);
1229                         break;
1230                 case 1:
1231                         werr = init_srv_conn_info_1(r->in.info_ctr->ctr.ctr1,
1232                                                     r->in.resume_handle,
1233                                                     r->out.totalentries);
1234                         break;
1235                 default:
1236                         return WERR_UNKNOWN_LEVEL;
1237         }
1238
1239         DEBUG(5,("_srvsvc_NetConnEnum: %d\n", __LINE__));
1240
1241         return werr;
1242 }
1243
1244 /*******************************************************************
1245  _srvsvc_NetSessEnum
1246 ********************************************************************/
1247
1248 WERROR _srvsvc_NetSessEnum(struct pipes_struct *p,
1249                            struct srvsvc_NetSessEnum *r)
1250 {
1251         WERROR werr;
1252
1253         DEBUG(5,("_srvsvc_NetSessEnum: %d\n", __LINE__));
1254
1255         if (!nt_token_check_sid(&global_sid_Builtin_Administrators,
1256                                 p->session_info->security_token)) {
1257                 DEBUG(1, ("Enumerating sessions only allowed for "
1258                           "administrators\n"));
1259                 return WERR_ACCESS_DENIED;
1260         }
1261
1262         switch (r->in.info_ctr->level) {
1263                 case 0:
1264                         werr = init_srv_sess_info_0(p,
1265                                                     r->in.info_ctr->ctr.ctr0,
1266                                                     r->in.resume_handle,
1267                                                     r->out.totalentries);
1268                         break;
1269                 case 1:
1270                         werr = init_srv_sess_info_1(p,
1271                                                     r->in.info_ctr->ctr.ctr1,
1272                                                     r->in.resume_handle,
1273                                                     r->out.totalentries);
1274                         break;
1275                 default:
1276                         return WERR_UNKNOWN_LEVEL;
1277         }
1278
1279         DEBUG(5,("_srvsvc_NetSessEnum: %d\n", __LINE__));
1280
1281         return werr;
1282 }
1283
1284 /*******************************************************************
1285  _srvsvc_NetSessDel
1286 ********************************************************************/
1287
1288 WERROR _srvsvc_NetSessDel(struct pipes_struct *p,
1289                           struct srvsvc_NetSessDel *r)
1290 {
1291         struct sessionid *session_list;
1292         int num_sessions, snum;
1293         const char *username;
1294         const char *machine;
1295         bool not_root = False;
1296         WERROR werr;
1297
1298         username = r->in.user;
1299         machine = r->in.client;
1300
1301         /* strip leading backslashes if any */
1302         if (machine && machine[0] == '\\' && machine[1] == '\\') {
1303                 machine += 2;
1304         }
1305
1306         num_sessions = list_sessions(p->mem_ctx, &session_list);
1307
1308         DEBUG(5,("_srvsvc_NetSessDel: %d\n", __LINE__));
1309
1310         werr = WERR_ACCESS_DENIED;
1311
1312         /* fail out now if you are not root or not a domain admin */
1313
1314         if ((p->session_info->utok.uid != sec_initial_uid()) &&
1315                 ( ! nt_token_check_domain_rid(p->session_info->security_token,
1316                                               DOMAIN_RID_ADMINS))) {
1317
1318                 goto done;
1319         }
1320
1321         for (snum = 0; snum < num_sessions; snum++) {
1322
1323                 if ((strequal(session_list[snum].username, username) || username[0] == '\0' ) &&
1324                     strequal(session_list[snum].remote_machine, machine)) {
1325
1326                         NTSTATUS ntstat;
1327
1328                         if (p->session_info->utok.uid != sec_initial_uid()) {
1329                                 not_root = True;
1330                                 become_root();
1331                         }
1332
1333                         ntstat = messaging_send(p->msg_ctx,
1334                                                 session_list[snum].pid,
1335                                                 MSG_SHUTDOWN, &data_blob_null);
1336
1337                         if (NT_STATUS_IS_OK(ntstat))
1338                                 werr = WERR_OK;
1339
1340                         if (not_root)
1341                                 unbecome_root();
1342                 }
1343         }
1344
1345         DEBUG(5,("_srvsvc_NetSessDel: %d\n", __LINE__));
1346
1347 done:
1348
1349         return werr;
1350 }
1351
1352 /*******************************************************************
1353  _srvsvc_NetShareEnumAll
1354 ********************************************************************/
1355
1356 WERROR _srvsvc_NetShareEnumAll(struct pipes_struct *p,
1357                                struct srvsvc_NetShareEnumAll *r)
1358 {
1359         WERROR werr;
1360
1361         DEBUG(5,("_srvsvc_NetShareEnumAll: %d\n", __LINE__));
1362
1363         if (!pipe_access_check(p)) {
1364                 DEBUG(3, ("access denied to _srvsvc_NetShareEnumAll\n"));
1365                 return WERR_ACCESS_DENIED;
1366         }
1367
1368         /* Create the list of shares for the response. */
1369         werr = init_srv_share_info_ctr(p,
1370                                        r->in.info_ctr,
1371                                        r->in.resume_handle,
1372                                        r->out.totalentries,
1373                                        true);
1374
1375         DEBUG(5,("_srvsvc_NetShareEnumAll: %d\n", __LINE__));
1376
1377         return werr;
1378 }
1379
1380 /*******************************************************************
1381  _srvsvc_NetShareEnum
1382 ********************************************************************/
1383
1384 WERROR _srvsvc_NetShareEnum(struct pipes_struct *p,
1385                             struct srvsvc_NetShareEnum *r)
1386 {
1387         WERROR werr;
1388
1389         DEBUG(5,("_srvsvc_NetShareEnum: %d\n", __LINE__));
1390
1391         if (!pipe_access_check(p)) {
1392                 DEBUG(3, ("access denied to _srvsvc_NetShareEnum\n"));
1393                 return WERR_ACCESS_DENIED;
1394         }
1395
1396         /* Create the list of shares for the response. */
1397         werr = init_srv_share_info_ctr(p,
1398                                        r->in.info_ctr,
1399                                        r->in.resume_handle,
1400                                        r->out.totalentries,
1401                                        false);
1402
1403         DEBUG(5,("_srvsvc_NetShareEnum: %d\n", __LINE__));
1404
1405         return werr;
1406 }
1407
1408 /*******************************************************************
1409  _srvsvc_NetShareGetInfo
1410 ********************************************************************/
1411
1412 WERROR _srvsvc_NetShareGetInfo(struct pipes_struct *p,
1413                                struct srvsvc_NetShareGetInfo *r)
1414 {
1415         WERROR status = WERR_OK;
1416         char *share_name = NULL;
1417         int snum;
1418         union srvsvc_NetShareInfo *info = r->out.info;
1419
1420         DEBUG(5,("_srvsvc_NetShareGetInfo: %d\n", __LINE__));
1421
1422         if (!r->in.share_name) {
1423                 return WERR_INVALID_NAME;
1424         }
1425
1426         snum = find_service(talloc_tos(), r->in.share_name, &share_name);
1427         if (!share_name) {
1428                 return WERR_NOMEM;
1429         }
1430         if (snum < 0) {
1431                 return WERR_INVALID_NAME;
1432         }
1433
1434         switch (r->in.level) {
1435                 case 0:
1436                         info->info0 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo0);
1437                         W_ERROR_HAVE_NO_MEMORY(info->info0);
1438                         init_srv_share_info_0(p, info->info0, snum);
1439                         break;
1440                 case 1:
1441                         info->info1 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo1);
1442                         W_ERROR_HAVE_NO_MEMORY(info->info1);
1443                         init_srv_share_info_1(p, info->info1, snum);
1444                         break;
1445                 case 2:
1446                         info->info2 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo2);
1447                         W_ERROR_HAVE_NO_MEMORY(info->info2);
1448                         init_srv_share_info_2(p, info->info2, snum);
1449                         break;
1450                 case 501:
1451                         info->info501 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo501);
1452                         W_ERROR_HAVE_NO_MEMORY(info->info501);
1453                         init_srv_share_info_501(p, info->info501, snum);
1454                         break;
1455                 case 502:
1456                         info->info502 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo502);
1457                         W_ERROR_HAVE_NO_MEMORY(info->info502);
1458                         init_srv_share_info_502(p, info->info502, snum);
1459                         break;
1460                 case 1004:
1461                         info->info1004 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo1004);
1462                         W_ERROR_HAVE_NO_MEMORY(info->info1004);
1463                         init_srv_share_info_1004(p, info->info1004, snum);
1464                         break;
1465                 case 1005:
1466                         info->info1005 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo1005);
1467                         W_ERROR_HAVE_NO_MEMORY(info->info1005);
1468                         init_srv_share_info_1005(p, info->info1005, snum);
1469                         break;
1470                 case 1006:
1471                         info->info1006 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo1006);
1472                         W_ERROR_HAVE_NO_MEMORY(info->info1006);
1473                         init_srv_share_info_1006(p, info->info1006, snum);
1474                         break;
1475                 case 1007:
1476                         info->info1007 = TALLOC_P(p->mem_ctx, struct srvsvc_NetShareInfo1007);
1477                         W_ERROR_HAVE_NO_MEMORY(info->info1007);
1478                         init_srv_share_info_1007(p, info->info1007, snum);
1479                         break;
1480                 case 1501:
1481                         init_srv_share_info_1501(p, info->info1501, snum);
1482                         break;
1483                 default:
1484                         DEBUG(5,("_srvsvc_NetShareGetInfo: unsupported switch value %d\n",
1485                                 r->in.level));
1486                         status = WERR_UNKNOWN_LEVEL;
1487                         break;
1488         }
1489
1490         DEBUG(5,("_srvsvc_NetShareGetInfo: %d\n", __LINE__));
1491
1492         return status;
1493 }
1494
1495 /*******************************************************************
1496  Check a given DOS pathname is valid for a share.
1497 ********************************************************************/
1498
1499 char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname)
1500 {
1501         char *ptr = NULL;
1502
1503         if (!dos_pathname) {
1504                 return NULL;
1505         }
1506
1507         ptr = talloc_strdup(ctx, dos_pathname);
1508         if (!ptr) {
1509                 return NULL;
1510         }
1511         /* Convert any '\' paths to '/' */
1512         unix_format(ptr);
1513         ptr = unix_clean_name(ctx, ptr);
1514         if (!ptr) {
1515                 return NULL;
1516         }
1517
1518         /* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */
1519         if (strlen(ptr) > 2 && ptr[1] == ':' && ptr[0] != '/')
1520                 ptr += 2;
1521
1522         /* Only absolute paths allowed. */
1523         if (*ptr != '/')
1524                 return NULL;
1525
1526         return ptr;
1527 }
1528
1529 /*******************************************************************
1530  _srvsvc_NetShareSetInfo. Modify share details.
1531 ********************************************************************/
1532
1533 WERROR _srvsvc_NetShareSetInfo(struct pipes_struct *p,
1534                                struct srvsvc_NetShareSetInfo *r)
1535 {
1536         char *command = NULL;
1537         char *share_name = NULL;
1538         char *comment = NULL;
1539         const char *pathname = NULL;
1540         int type;
1541         int snum;
1542         int ret;
1543         char *path = NULL;
1544         struct security_descriptor *psd = NULL;
1545         bool is_disk_op = False;
1546         int max_connections = 0;
1547         TALLOC_CTX *ctx = p->mem_ctx;
1548         union srvsvc_NetShareInfo *info = r->in.info;
1549
1550         DEBUG(5,("_srvsvc_NetShareSetInfo: %d\n", __LINE__));
1551
1552         if (!r->in.share_name) {
1553                 return WERR_INVALID_NAME;
1554         }
1555
1556         if (r->out.parm_error) {
1557                 *r->out.parm_error = 0;
1558         }
1559
1560         if ( strequal(r->in.share_name,"IPC$")
1561                 || ( lp_enable_asu_support() && strequal(r->in.share_name,"ADMIN$") )
1562                 || strequal(r->in.share_name,"global") )
1563         {
1564                 DEBUG(5,("_srvsvc_NetShareSetInfo: share %s cannot be "
1565                         "modified by a remote user.\n",
1566                         r->in.share_name ));
1567                 return WERR_ACCESS_DENIED;
1568         }
1569
1570         snum = find_service(talloc_tos(), r->in.share_name, &share_name);
1571         if (!share_name) {
1572                 return WERR_NOMEM;
1573         }
1574
1575         /* Does this share exist ? */
1576         if (snum < 0)
1577                 return WERR_NET_NAME_NOT_FOUND;
1578
1579         /* No change to printer shares. */
1580         if (lp_print_ok(snum))
1581                 return WERR_ACCESS_DENIED;
1582
1583         is_disk_op = security_token_has_privilege(p->session_info->security_token, SEC_PRIV_DISK_OPERATOR);
1584
1585         /* fail out now if you are not root and not a disk op */
1586
1587         if ( p->session_info->utok.uid != sec_initial_uid() && !is_disk_op ) {
1588                 DEBUG(2,("_srvsvc_NetShareSetInfo: uid %u doesn't have the "
1589                         "SeDiskOperatorPrivilege privilege needed to modify "
1590                         "share %s\n",
1591                         (unsigned int)p->session_info->utok.uid,
1592                         share_name ));
1593                 return WERR_ACCESS_DENIED;
1594         }
1595
1596         switch (r->in.level) {
1597         case 1:
1598                 pathname = talloc_strdup(ctx, lp_pathname(snum));
1599                 comment = talloc_strdup(ctx, info->info1->comment);
1600                 type = info->info1->type;
1601                 psd = NULL;
1602                 break;
1603         case 2:
1604                 comment = talloc_strdup(ctx, info->info2->comment);
1605                 pathname = info->info2->path;
1606                 type = info->info2->type;
1607                 max_connections = (info->info2->max_users == (uint32_t)-1) ?
1608                         0 : info->info2->max_users;
1609                 psd = NULL;
1610                 break;
1611 #if 0
1612                 /* not supported on set but here for completeness */
1613         case 501:
1614                 comment = talloc_strdup(ctx, info->info501->comment);
1615                 type = info->info501->type;
1616                 psd = NULL;
1617                 break;
1618 #endif
1619         case 502:
1620                 comment = talloc_strdup(ctx, info->info502->comment);
1621                 pathname = info->info502->path;
1622                 type = info->info502->type;
1623                 psd = info->info502->sd_buf.sd;
1624                 map_generic_share_sd_bits(psd);
1625                 break;
1626         case 1004:
1627                 pathname = talloc_strdup(ctx, lp_pathname(snum));
1628                 comment = talloc_strdup(ctx, info->info1004->comment);
1629                 type = STYPE_DISKTREE;
1630                 break;
1631         case 1005:
1632                 /* XP re-sets the csc policy even if it wasn't changed by the
1633                    user, so we must compare it to see if it's what is set in
1634                    smb.conf, so that we can contine other ops like setting
1635                    ACLs on a share */
1636                 if (((info->info1005->dfs_flags &
1637                       SHARE_1005_CSC_POLICY_MASK) >>
1638                      SHARE_1005_CSC_POLICY_SHIFT) == lp_csc_policy(snum))
1639                         return WERR_OK;
1640                 else {
1641                         DEBUG(3, ("_srvsvc_NetShareSetInfo: client is trying to change csc policy from the network; must be done with smb.conf\n"));
1642                         return WERR_ACCESS_DENIED;
1643                 }
1644         case 1006:
1645         case 1007:
1646                 return WERR_ACCESS_DENIED;
1647         case 1501:
1648                 pathname = talloc_strdup(ctx, lp_pathname(snum));
1649                 comment = talloc_strdup(ctx, lp_comment(snum));
1650                 psd = info->info1501->sd;
1651                 map_generic_share_sd_bits(psd);
1652                 type = STYPE_DISKTREE;
1653                 break;
1654         default:
1655                 DEBUG(5,("_srvsvc_NetShareSetInfo: unsupported switch value %d\n",
1656                         r->in.level));
1657                 return WERR_UNKNOWN_LEVEL;
1658         }
1659
1660         /* We can only modify disk shares. */
1661         if (type != STYPE_DISKTREE) {
1662                 DEBUG(5,("_srvsvc_NetShareSetInfo: share %s is not a "
1663                         "disk share\n",
1664                         share_name ));
1665                 return WERR_ACCESS_DENIED;
1666         }
1667
1668         if (comment == NULL) {
1669                 return WERR_NOMEM;
1670         }
1671
1672         /* Check if the pathname is valid. */
1673         if (!(path = valid_share_pathname(p->mem_ctx, pathname ))) {
1674                 DEBUG(5,("_srvsvc_NetShareSetInfo: invalid pathname %s\n",
1675                         pathname ));
1676                 return WERR_OBJECT_PATH_INVALID;
1677         }
1678
1679         /* Ensure share name, pathname and comment don't contain '"' characters. */
1680         string_replace(share_name, '"', ' ');
1681         string_replace(path, '"', ' ');
1682         string_replace(comment, '"', ' ');
1683
1684         DEBUG(10,("_srvsvc_NetShareSetInfo: change share command = %s\n",
1685                 lp_change_share_cmd() ? lp_change_share_cmd() : "NULL" ));
1686
1687         /* Only call modify function if something changed. */
1688
1689         if (strcmp(path, lp_pathname(snum)) || strcmp(comment, lp_comment(snum))
1690                         || (lp_max_connections(snum) != max_connections)) {
1691                 if (!lp_change_share_cmd() || !*lp_change_share_cmd()) {
1692                         DEBUG(10,("_srvsvc_NetShareSetInfo: No change share command\n"));
1693                         return WERR_ACCESS_DENIED;
1694                 }
1695
1696                 command = talloc_asprintf(p->mem_ctx,
1697                                 "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
1698                                 lp_change_share_cmd(),
1699                                 get_dyn_CONFIGFILE(),
1700                                 share_name,
1701                                 path,
1702                                 comment ? comment : "",
1703                                 max_connections);
1704                 if (!command) {
1705                         return WERR_NOMEM;
1706                 }
1707
1708                 DEBUG(10,("_srvsvc_NetShareSetInfo: Running [%s]\n", command ));
1709
1710                 /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
1711
1712                 if (is_disk_op)
1713                         become_root();
1714
1715                 if ( (ret = smbrun(command, NULL)) == 0 ) {
1716                         /* Tell everyone we updated smb.conf. */
1717                         message_send_all(p->msg_ctx, MSG_SMB_CONF_UPDATED,
1718                                          NULL, 0, NULL);
1719                 }
1720
1721                 if ( is_disk_op )
1722                         unbecome_root();
1723
1724                 /********* END SeDiskOperatorPrivilege BLOCK *********/
1725
1726                 DEBUG(3,("_srvsvc_NetShareSetInfo: Running [%s] returned (%d)\n",
1727                         command, ret ));
1728
1729                 TALLOC_FREE(command);
1730
1731                 if ( ret != 0 )
1732                         return WERR_ACCESS_DENIED;
1733         } else {
1734                 DEBUG(10,("_srvsvc_NetShareSetInfo: No change to share name (%s)\n",
1735                         share_name ));
1736         }
1737
1738         /* Replace SD if changed. */
1739         if (psd) {
1740                 struct security_descriptor *old_sd;
1741                 size_t sd_size;
1742
1743                 old_sd = get_share_security(p->mem_ctx, lp_servicename(snum), &sd_size);
1744
1745                 if (old_sd && !security_descriptor_equal(old_sd, psd)) {
1746                         if (!set_share_security(share_name, psd))
1747                                 DEBUG(0,("_srvsvc_NetShareSetInfo: Failed to change security info in share %s.\n",
1748                                         share_name ));
1749                 }
1750         }
1751
1752         DEBUG(5,("_srvsvc_NetShareSetInfo: %d\n", __LINE__));
1753
1754         return WERR_OK;
1755 }
1756
1757 /*******************************************************************
1758  _srvsvc_NetShareAdd.
1759  Call 'add_share_command "sharename" "pathname"
1760  "comment" "max connections = "
1761 ********************************************************************/
1762
1763 WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
1764                            struct srvsvc_NetShareAdd *r)
1765 {
1766         char *command = NULL;
1767         char *share_name_in = NULL;
1768         char *share_name = NULL;
1769         char *comment = NULL;
1770         char *pathname = NULL;
1771         int type;
1772         int snum;
1773         int ret;
1774         char *path;
1775         struct security_descriptor *psd = NULL;
1776         bool is_disk_op;
1777         int max_connections = 0;
1778         TALLOC_CTX *ctx = p->mem_ctx;
1779
1780         DEBUG(5,("_srvsvc_NetShareAdd: %d\n", __LINE__));
1781
1782         if (r->out.parm_error) {
1783                 *r->out.parm_error = 0;
1784         }
1785
1786         is_disk_op = security_token_has_privilege(p->session_info->security_token, SEC_PRIV_DISK_OPERATOR);
1787
1788         if (p->session_info->utok.uid != sec_initial_uid()  && !is_disk_op )
1789                 return WERR_ACCESS_DENIED;
1790
1791         if (!lp_add_share_cmd() || !*lp_add_share_cmd()) {
1792                 DEBUG(10,("_srvsvc_NetShareAdd: No add share command\n"));
1793                 return WERR_ACCESS_DENIED;
1794         }
1795
1796         switch (r->in.level) {
1797         case 0:
1798                 /* No path. Not enough info in a level 0 to do anything. */
1799                 return WERR_ACCESS_DENIED;
1800         case 1:
1801                 /* Not enough info in a level 1 to do anything. */
1802                 return WERR_ACCESS_DENIED;
1803         case 2:
1804                 share_name_in = talloc_strdup(ctx, r->in.info->info2->name);
1805                 comment = talloc_strdup(ctx, r->in.info->info2->comment);
1806                 pathname = talloc_strdup(ctx, r->in.info->info2->path);
1807                 max_connections = (r->in.info->info2->max_users == (uint32_t)-1) ?
1808                         0 : r->in.info->info2->max_users;
1809                 type = r->in.info->info2->type;
1810                 break;
1811         case 501:
1812                 /* No path. Not enough info in a level 501 to do anything. */
1813                 return WERR_ACCESS_DENIED;
1814         case 502:
1815                 share_name_in = talloc_strdup(ctx, r->in.info->info502->name);
1816                 comment = talloc_strdup(ctx, r->in.info->info502->comment);
1817                 pathname = talloc_strdup(ctx, r->in.info->info502->path);
1818                 max_connections = (r->in.info->info502->max_users == (uint32_t)-1) ?
1819                         0 : r->in.info->info502->max_users;
1820                 type = r->in.info->info502->type;
1821                 psd = r->in.info->info502->sd_buf.sd;
1822                 map_generic_share_sd_bits(psd);
1823                 break;
1824
1825                 /* none of the following contain share names.  NetShareAdd does not have a separate parameter for the share name */
1826
1827         case 1004:
1828         case 1005:
1829         case 1006:
1830         case 1007:
1831                 return WERR_ACCESS_DENIED;
1832         case 1501:
1833                 /* DFS only level. */
1834                 return WERR_ACCESS_DENIED;
1835         default:
1836                 DEBUG(5,("_srvsvc_NetShareAdd: unsupported switch value %d\n",
1837                         r->in.level));
1838                 return WERR_UNKNOWN_LEVEL;
1839         }
1840
1841         /* check for invalid share names */
1842
1843         if (!share_name_in || !validate_net_name(share_name_in,
1844                                 INVALID_SHARENAME_CHARS,
1845                                 strlen(share_name_in))) {
1846                 DEBUG(5,("_srvsvc_NetShareAdd: Bad sharename \"%s\"\n",
1847                                         share_name_in ? share_name_in : ""));
1848                 return WERR_INVALID_NAME;
1849         }
1850
1851         if (strequal(share_name_in,"IPC$") || strequal(share_name_in,"global")
1852                         || (lp_enable_asu_support() &&
1853                                         strequal(share_name_in,"ADMIN$"))) {
1854                 return WERR_ACCESS_DENIED;
1855         }
1856
1857         snum = find_service(ctx, share_name_in, &share_name);
1858         if (!share_name) {
1859                 return WERR_NOMEM;
1860         }
1861
1862         /* Share already exists. */
1863         if (snum >= 0) {
1864                 return WERR_FILE_EXISTS;
1865         }
1866
1867         /* We can only add disk shares. */
1868         if (type != STYPE_DISKTREE) {
1869                 return WERR_ACCESS_DENIED;
1870         }
1871
1872         /* Check if the pathname is valid. */
1873         if (!(path = valid_share_pathname(p->mem_ctx, pathname))) {
1874                 return WERR_OBJECT_PATH_INVALID;
1875         }
1876
1877         /* Ensure share name, pathname and comment don't contain '"' characters. */
1878         string_replace(share_name_in, '"', ' ');
1879         string_replace(share_name, '"', ' ');
1880         string_replace(path, '"', ' ');
1881         if (comment) {
1882                 string_replace(comment, '"', ' ');
1883         }
1884
1885         command = talloc_asprintf(ctx,
1886                         "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
1887                         lp_add_share_cmd(),
1888                         get_dyn_CONFIGFILE(),
1889                         share_name_in,
1890                         path,
1891                         comment ? comment : "",
1892                         max_connections);
1893         if (!command) {
1894                 return WERR_NOMEM;
1895         }
1896
1897         DEBUG(10,("_srvsvc_NetShareAdd: Running [%s]\n", command ));
1898
1899         /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
1900
1901         if ( is_disk_op )
1902                 become_root();
1903
1904         /* FIXME: use libnetconf here - gd */
1905
1906         if ( (ret = smbrun(command, NULL)) == 0 ) {
1907                 /* Tell everyone we updated smb.conf. */
1908                 message_send_all(p->msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0,
1909                                  NULL);
1910         }
1911
1912         if ( is_disk_op )
1913                 unbecome_root();
1914
1915         /********* END SeDiskOperatorPrivilege BLOCK *********/
1916
1917         DEBUG(3,("_srvsvc_NetShareAdd: Running [%s] returned (%d)\n",
1918                 command, ret ));
1919
1920         TALLOC_FREE(command);
1921
1922         if ( ret != 0 )
1923                 return WERR_ACCESS_DENIED;
1924
1925         if (psd) {
1926                 /* Note we use share_name here, not share_name_in as
1927                    we need a canonicalized name for setting security. */
1928                 if (!set_share_security(share_name, psd)) {
1929                         DEBUG(0,("_srvsvc_NetShareAdd: Failed to add security info to share %s.\n",
1930                                 share_name ));
1931                 }
1932         }
1933
1934         /*
1935          * We don't call reload_services() here, the message will
1936          * cause this to be done before the next packet is read
1937          * from the client. JRA.
1938          */
1939
1940         DEBUG(5,("_srvsvc_NetShareAdd: %d\n", __LINE__));
1941
1942         return WERR_OK;
1943 }
1944
1945 /*******************************************************************
1946  _srvsvc_NetShareDel
1947  Call "delete share command" with the share name as
1948  a parameter.
1949 ********************************************************************/
1950
1951 WERROR _srvsvc_NetShareDel(struct pipes_struct *p,
1952                            struct srvsvc_NetShareDel *r)
1953 {
1954         char *command = NULL;
1955         char *share_name = NULL;
1956         int ret;
1957         int snum;
1958         bool is_disk_op;
1959         struct share_params *params;
1960         TALLOC_CTX *ctx = p->mem_ctx;
1961
1962         DEBUG(5,("_srvsvc_NetShareDel: %d\n", __LINE__));
1963
1964         if (!r->in.share_name) {
1965                 return WERR_NET_NAME_NOT_FOUND;
1966         }
1967
1968         if ( strequal(r->in.share_name,"IPC$")
1969                 || ( lp_enable_asu_support() && strequal(r->in.share_name,"ADMIN$") )
1970                 || strequal(r->in.share_name,"global") )
1971         {
1972                 return WERR_ACCESS_DENIED;
1973         }
1974
1975         snum = find_service(talloc_tos(), r->in.share_name, &share_name);
1976         if (!share_name) {
1977                 return WERR_NOMEM;
1978         }
1979
1980         if (snum < 0) {
1981                 return WERR_NO_SUCH_SHARE;
1982         }
1983
1984         if (!(params = get_share_params(p->mem_ctx, share_name))) {
1985                 return WERR_NO_SUCH_SHARE;
1986         }
1987
1988         /* No change to printer shares. */
1989         if (lp_print_ok(snum))
1990                 return WERR_ACCESS_DENIED;
1991
1992         is_disk_op = security_token_has_privilege(p->session_info->security_token, SEC_PRIV_DISK_OPERATOR);
1993
1994         if (p->session_info->utok.uid != sec_initial_uid()  && !is_disk_op )
1995                 return WERR_ACCESS_DENIED;
1996
1997         if (!lp_delete_share_cmd() || !*lp_delete_share_cmd()) {
1998                 DEBUG(10,("_srvsvc_NetShareDel: No delete share command\n"));
1999                 return WERR_ACCESS_DENIED;
2000         }
2001
2002         command = talloc_asprintf(ctx,
2003                         "%s \"%s\" \"%s\"",
2004                         lp_delete_share_cmd(),
2005                         get_dyn_CONFIGFILE(),
2006                         lp_servicename(snum));
2007         if (!command) {
2008                 return WERR_NOMEM;
2009         }
2010
2011         DEBUG(10,("_srvsvc_NetShareDel: Running [%s]\n", command ));
2012
2013         /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
2014
2015         if ( is_disk_op )
2016                 become_root();
2017
2018         if ( (ret = smbrun(command, NULL)) == 0 ) {
2019                 /* Tell everyone we updated smb.conf. */
2020                 message_send_all(p->msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0,
2021                                  NULL);
2022         }
2023
2024         if ( is_disk_op )
2025                 unbecome_root();
2026
2027         /********* END SeDiskOperatorPrivilege BLOCK *********/
2028
2029         DEBUG(3,("_srvsvc_NetShareDel: Running [%s] returned (%d)\n", command, ret ));
2030
2031         if ( ret != 0 )
2032                 return WERR_ACCESS_DENIED;
2033
2034         /* Delete the SD in the database. */
2035         delete_share_security(lp_servicename(params->service));
2036
2037         lp_killservice(params->service);
2038
2039         return WERR_OK;
2040 }
2041
2042 /*******************************************************************
2043  _srvsvc_NetShareDelSticky
2044 ********************************************************************/
2045
2046 WERROR _srvsvc_NetShareDelSticky(struct pipes_struct *p,
2047                                  struct srvsvc_NetShareDelSticky *r)
2048 {
2049         struct srvsvc_NetShareDel q;
2050
2051         DEBUG(5,("_srvsvc_NetShareDelSticky: %d\n", __LINE__));
2052
2053         q.in.server_unc         = r->in.server_unc;
2054         q.in.share_name         = r->in.share_name;
2055         q.in.reserved           = r->in.reserved;
2056
2057         return _srvsvc_NetShareDel(p, &q);
2058 }
2059
2060 /*******************************************************************
2061  _srvsvc_NetRemoteTOD
2062 ********************************************************************/
2063
2064 WERROR _srvsvc_NetRemoteTOD(struct pipes_struct *p,
2065                             struct srvsvc_NetRemoteTOD *r)
2066 {
2067         struct srvsvc_NetRemoteTODInfo *tod;
2068         struct tm *t;
2069         time_t unixdate = time(NULL);
2070
2071         /* We do this call first as if we do it *after* the gmtime call
2072            it overwrites the pointed-to values. JRA */
2073
2074         uint32 zone = get_time_zone(unixdate)/60;
2075
2076         DEBUG(5,("_srvsvc_NetRemoteTOD: %d\n", __LINE__));
2077
2078         if ( !(tod = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetRemoteTODInfo)) )
2079                 return WERR_NOMEM;
2080
2081         *r->out.info = tod;
2082
2083         DEBUG(5,("_srvsvc_NetRemoteTOD: %d\n", __LINE__));
2084
2085         t = gmtime(&unixdate);
2086
2087         /* set up the */
2088         tod->elapsed    = unixdate;
2089         tod->msecs      = 0;
2090         tod->hours      = t->tm_hour;
2091         tod->mins       = t->tm_min;
2092         tod->secs       = t->tm_sec;
2093         tod->hunds      = 0;
2094         tod->timezone   = zone;
2095         tod->tinterval  = 10000;
2096         tod->day        = t->tm_mday;
2097         tod->month      = t->tm_mon + 1;
2098         tod->year       = 1900+t->tm_year;
2099         tod->weekday    = t->tm_wday;
2100
2101         DEBUG(5,("_srvsvc_NetRemoteTOD: %d\n", __LINE__));
2102
2103         return WERR_OK;
2104 }
2105
2106 /***********************************************************************************
2107  _srvsvc_NetGetFileSecurity
2108  Win9x NT tools get security descriptor.
2109 ***********************************************************************************/
2110
2111 WERROR _srvsvc_NetGetFileSecurity(struct pipes_struct *p,
2112                                   struct srvsvc_NetGetFileSecurity *r)
2113 {
2114         struct smb_filename *smb_fname = NULL;
2115         struct security_descriptor *psd = NULL;
2116         size_t sd_size;
2117         char *servicename = NULL;
2118         SMB_STRUCT_STAT st;
2119         NTSTATUS nt_status;
2120         WERROR werr;
2121         connection_struct *conn = NULL;
2122         struct sec_desc_buf *sd_buf = NULL;
2123         files_struct *fsp = NULL;
2124         int snum;
2125         char *oldcwd = NULL;
2126
2127         ZERO_STRUCT(st);
2128
2129         if (!r->in.share) {
2130                 werr = WERR_NET_NAME_NOT_FOUND;
2131                 goto error_exit;
2132         }
2133         snum = find_service(talloc_tos(), r->in.share, &servicename);
2134         if (!servicename) {
2135                 werr = WERR_NOMEM;
2136                 goto error_exit;
2137         }
2138         if (snum == -1) {
2139                 DEBUG(10, ("Could not find service %s\n", servicename));
2140                 werr = WERR_NET_NAME_NOT_FOUND;
2141                 goto error_exit;
2142         }
2143
2144         nt_status = create_conn_struct(talloc_tos(), &conn, snum,
2145                                        lp_pathname(snum), p->session_info,
2146                                        &oldcwd);
2147         if (!NT_STATUS_IS_OK(nt_status)) {
2148                 DEBUG(10, ("create_conn_struct failed: %s\n",
2149                            nt_errstr(nt_status)));
2150                 werr = ntstatus_to_werror(nt_status);
2151                 goto error_exit;
2152         }
2153
2154         nt_status = filename_convert(talloc_tos(),
2155                                         conn,
2156                                         false,
2157                                         r->in.file,
2158                                         0,
2159                                         NULL,
2160                                         &smb_fname);
2161         if (!NT_STATUS_IS_OK(nt_status)) {
2162                 werr = ntstatus_to_werror(nt_status);
2163                 goto error_exit;
2164         }
2165
2166         nt_status = SMB_VFS_CREATE_FILE(
2167                 conn,                                   /* conn */
2168                 NULL,                                   /* req */
2169                 0,                                      /* root_dir_fid */
2170                 smb_fname,                              /* fname */
2171                 FILE_READ_ATTRIBUTES,                   /* access_mask */
2172                 FILE_SHARE_READ|FILE_SHARE_WRITE,       /* share_access */
2173                 FILE_OPEN,                              /* create_disposition*/
2174                 0,                                      /* create_options */
2175                 0,                                      /* file_attributes */
2176                 INTERNAL_OPEN_ONLY,                     /* oplock_request */
2177                 0,                                      /* allocation_size */
2178                 0,                                      /* private_flags */
2179                 NULL,                                   /* sd */
2180                 NULL,                                   /* ea_list */
2181                 &fsp,                                   /* result */
2182                 NULL);                                  /* pinfo */
2183
2184         if (!NT_STATUS_IS_OK(nt_status)) {
2185                 DEBUG(3,("_srvsvc_NetGetFileSecurity: can't open %s\n",
2186                          smb_fname_str_dbg(smb_fname)));
2187                 werr = ntstatus_to_werror(nt_status);
2188                 goto error_exit;
2189         }
2190
2191         nt_status = SMB_VFS_FGET_NT_ACL(fsp,
2192                                        (SECINFO_OWNER
2193                                         |SECINFO_GROUP
2194                                         |SECINFO_DACL), &psd);
2195
2196         if (!NT_STATUS_IS_OK(nt_status)) {
2197                 DEBUG(3,("_srvsvc_NetGetFileSecurity: Unable to get NT ACL "
2198                         "for file %s\n", smb_fname_str_dbg(smb_fname)));
2199                 werr = ntstatus_to_werror(nt_status);
2200                 goto error_exit;
2201         }
2202
2203         sd_size = ndr_size_security_descriptor(psd, 0);
2204
2205         sd_buf = TALLOC_ZERO_P(p->mem_ctx, struct sec_desc_buf);
2206         if (!sd_buf) {
2207                 werr = WERR_NOMEM;
2208                 goto error_exit;
2209         }
2210
2211         sd_buf->sd_size = sd_size;
2212         sd_buf->sd = psd;
2213
2214         *r->out.sd_buf = sd_buf;
2215
2216         psd->dacl->revision = NT4_ACL_REVISION;
2217
2218         close_file(NULL, fsp, NORMAL_CLOSE);
2219         vfs_ChDir(conn, oldcwd);
2220         SMB_VFS_DISCONNECT(conn);
2221         conn_free(conn);
2222         werr = WERR_OK;
2223         goto done;
2224
2225 error_exit:
2226
2227         if (fsp) {
2228                 close_file(NULL, fsp, NORMAL_CLOSE);
2229         }
2230
2231         if (oldcwd) {
2232                 vfs_ChDir(conn, oldcwd);
2233         }
2234
2235         if (conn) {
2236                 SMB_VFS_DISCONNECT(conn);
2237                 conn_free(conn);
2238         }
2239
2240  done:
2241         TALLOC_FREE(smb_fname);
2242
2243         return werr;
2244 }
2245
2246 /***********************************************************************************
2247  _srvsvc_NetSetFileSecurity
2248  Win9x NT tools set security descriptor.
2249 ***********************************************************************************/
2250
2251 WERROR _srvsvc_NetSetFileSecurity(struct pipes_struct *p,
2252                                   struct srvsvc_NetSetFileSecurity *r)
2253 {
2254         struct smb_filename *smb_fname = NULL;
2255         char *servicename = NULL;
2256         files_struct *fsp = NULL;
2257         SMB_STRUCT_STAT st;
2258         NTSTATUS nt_status;
2259         WERROR werr;
2260         connection_struct *conn = NULL;
2261         int snum;
2262         char *oldcwd = NULL;
2263         struct security_descriptor *psd = NULL;
2264         uint32_t security_info_sent = 0;
2265
2266         ZERO_STRUCT(st);
2267
2268         if (!r->in.share) {
2269                 werr = WERR_NET_NAME_NOT_FOUND;
2270                 goto error_exit;
2271         }
2272
2273         snum = find_service(talloc_tos(), r->in.share, &servicename);
2274         if (!servicename) {
2275                 werr = WERR_NOMEM;
2276                 goto error_exit;
2277         }
2278
2279         if (snum == -1) {
2280                 DEBUG(10, ("Could not find service %s\n", servicename));
2281                 werr = WERR_NET_NAME_NOT_FOUND;
2282                 goto error_exit;
2283         }
2284
2285         nt_status = create_conn_struct(talloc_tos(), &conn, snum,
2286                                        lp_pathname(snum), p->session_info,
2287                                        &oldcwd);
2288         if (!NT_STATUS_IS_OK(nt_status)) {
2289                 DEBUG(10, ("create_conn_struct failed: %s\n",
2290                            nt_errstr(nt_status)));
2291                 werr = ntstatus_to_werror(nt_status);
2292                 goto error_exit;
2293         }
2294
2295         nt_status = filename_convert(talloc_tos(),
2296                                         conn,
2297                                         false,
2298                                         r->in.file,
2299                                         0,
2300                                         NULL,
2301                                         &smb_fname);
2302         if (!NT_STATUS_IS_OK(nt_status)) {
2303                 werr = ntstatus_to_werror(nt_status);
2304                 goto error_exit;
2305         }
2306
2307         nt_status = SMB_VFS_CREATE_FILE(
2308                 conn,                                   /* conn */
2309                 NULL,                                   /* req */
2310                 0,                                      /* root_dir_fid */
2311                 smb_fname,                              /* fname */
2312                 FILE_WRITE_ATTRIBUTES,                  /* access_mask */
2313                 FILE_SHARE_READ|FILE_SHARE_WRITE,       /* share_access */
2314                 FILE_OPEN,                              /* create_disposition*/
2315                 0,                                      /* create_options */
2316                 0,                                      /* file_attributes */
2317                 INTERNAL_OPEN_ONLY,                     /* oplock_request */
2318                 0,                                      /* allocation_size */
2319                 0,                                      /* private_flags */
2320                 NULL,                                   /* sd */
2321                 NULL,                                   /* ea_list */
2322                 &fsp,                                   /* result */
2323                 NULL);                                  /* pinfo */
2324
2325         if (!NT_STATUS_IS_OK(nt_status)) {
2326                 DEBUG(3,("_srvsvc_NetSetFileSecurity: can't open %s\n",
2327                          smb_fname_str_dbg(smb_fname)));
2328                 werr = ntstatus_to_werror(nt_status);
2329                 goto error_exit;
2330         }
2331
2332         psd = r->in.sd_buf->sd;
2333         security_info_sent = r->in.securityinformation;
2334
2335         if (psd->owner_sid==0) {
2336                 security_info_sent &= ~SECINFO_OWNER;
2337         }
2338         if (psd->group_sid==0) {
2339                 security_info_sent &= ~SECINFO_GROUP;
2340         }
2341         if (psd->sacl==0) {
2342                 security_info_sent &= ~SECINFO_SACL;
2343         }
2344         if (psd->dacl==0) {
2345                 security_info_sent &= ~SECINFO_DACL;
2346         }
2347
2348         /* Convert all the generic bits. */
2349         security_acl_map_generic(psd->dacl, &file_generic_mapping);
2350         security_acl_map_generic(psd->sacl, &file_generic_mapping);
2351
2352         nt_status = SMB_VFS_FSET_NT_ACL(fsp,
2353                                         security_info_sent,
2354                                         psd);
2355
2356         if (!NT_STATUS_IS_OK(nt_status) ) {
2357                 DEBUG(3,("_srvsvc_NetSetFileSecurity: Unable to set NT ACL "
2358                          "on file %s\n", r->in.share));
2359                 werr = WERR_ACCESS_DENIED;
2360                 goto error_exit;
2361         }
2362
2363         close_file(NULL, fsp, NORMAL_CLOSE);
2364         vfs_ChDir(conn, oldcwd);
2365         SMB_VFS_DISCONNECT(conn);
2366         conn_free(conn);
2367         werr = WERR_OK;
2368         goto done;
2369
2370 error_exit:
2371
2372         if (fsp) {
2373                 close_file(NULL, fsp, NORMAL_CLOSE);
2374         }
2375
2376         if (oldcwd) {
2377                 vfs_ChDir(conn, oldcwd);
2378         }
2379
2380         if (conn) {
2381                 SMB_VFS_DISCONNECT(conn);
2382                 conn_free(conn);
2383         }
2384
2385  done:
2386         TALLOC_FREE(smb_fname);
2387
2388         return werr;
2389 }
2390
2391 /***********************************************************************************
2392  It may be that we want to limit users to creating shares on certain areas of the UNIX file area.
2393  We could define areas by mapping Windows style disks to points on the UNIX directory hierarchy.
2394  These disks would the disks listed by this function.
2395  Users could then create shares relative to these disks.  Watch out for moving these disks around.
2396  "Nigel Williams" <nigel@veritas.com>.
2397 ***********************************************************************************/
2398
2399 static const char *server_disks[] = {"C:"};
2400
2401 static uint32 get_server_disk_count(void)
2402 {
2403         return sizeof(server_disks)/sizeof(server_disks[0]);
2404 }
2405
2406 static uint32 init_server_disk_enum(uint32 *resume)
2407 {
2408         uint32 server_disk_count = get_server_disk_count();
2409
2410         /*resume can be an offset into the list for now*/
2411
2412         if(*resume & 0x80000000)
2413                 *resume = 0;
2414
2415         if(*resume > server_disk_count)
2416                 *resume = server_disk_count;
2417
2418         return server_disk_count - *resume;
2419 }
2420
2421 static const char *next_server_disk_enum(uint32 *resume)
2422 {
2423         const char *disk;
2424
2425         if(init_server_disk_enum(resume) == 0)
2426                 return NULL;
2427
2428         disk = server_disks[*resume];
2429
2430         (*resume)++;
2431
2432         DEBUG(10, ("next_server_disk_enum: reporting disk %s. resume handle %d.\n", disk, *resume));
2433
2434         return disk;
2435 }
2436
2437 /********************************************************************
2438  _srvsvc_NetDiskEnum
2439 ********************************************************************/
2440
2441 WERROR _srvsvc_NetDiskEnum(struct pipes_struct *p,
2442                            struct srvsvc_NetDiskEnum *r)
2443 {
2444         uint32 i;
2445         const char *disk_name;
2446         TALLOC_CTX *ctx = p->mem_ctx;
2447         WERROR werr;
2448         uint32_t resume = r->in.resume_handle ? *r->in.resume_handle : 0;
2449
2450         werr = WERR_OK;
2451
2452         *r->out.totalentries = init_server_disk_enum(&resume);
2453
2454         r->out.info->disks = TALLOC_ZERO_ARRAY(ctx, struct srvsvc_NetDiskInfo0,
2455                                                MAX_SERVER_DISK_ENTRIES);
2456         W_ERROR_HAVE_NO_MEMORY(r->out.info->disks);
2457
2458         /*allow one struct srvsvc_NetDiskInfo0 for null terminator*/
2459
2460         r->out.info->count = 0;
2461
2462         for(i = 0; i < MAX_SERVER_DISK_ENTRIES -1 && (disk_name = next_server_disk_enum(&resume)); i++) {
2463
2464                 r->out.info->count++;
2465
2466                 /*copy disk name into a unicode string*/
2467
2468                 r->out.info->disks[i].disk = talloc_strdup(ctx, disk_name);
2469                 W_ERROR_HAVE_NO_MEMORY(r->out.info->disks[i].disk);
2470         }
2471
2472         /* add a terminating null string.  Is this there if there is more data to come? */
2473
2474         r->out.info->count++;
2475
2476         r->out.info->disks[i].disk = talloc_strdup(ctx, "");
2477         W_ERROR_HAVE_NO_MEMORY(r->out.info->disks[i].disk);
2478
2479         if (r->out.resume_handle) {
2480                 *r->out.resume_handle = resume;
2481         }
2482
2483         return werr;
2484 }
2485
2486 /********************************************************************
2487  _srvsvc_NetNameValidate
2488 ********************************************************************/
2489
2490 WERROR _srvsvc_NetNameValidate(struct pipes_struct *p,
2491                                struct srvsvc_NetNameValidate *r)
2492 {
2493         switch (r->in.name_type) {
2494         case 0x9:
2495                 if (!validate_net_name(r->in.name, INVALID_SHARENAME_CHARS,
2496                                        strlen_m(r->in.name)))
2497                 {
2498                         DEBUG(5,("_srvsvc_NetNameValidate: Bad sharename \"%s\"\n",
2499                                 r->in.name));
2500                         return WERR_INVALID_NAME;
2501                 }
2502                 break;
2503
2504         default:
2505                 return WERR_UNKNOWN_LEVEL;
2506         }
2507
2508         return WERR_OK;
2509 }
2510
2511 /*******************************************************************
2512 ********************************************************************/
2513
2514 struct enum_file_close_state {
2515         struct srvsvc_NetFileClose *r;
2516         struct messaging_context *msg_ctx;
2517 };
2518
2519 static void enum_file_close_fn( const struct share_mode_entry *e,
2520                           const char *sharepath, const char *fname,
2521                           void *private_data )
2522 {
2523         char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
2524         struct enum_file_close_state *state =
2525                 (struct enum_file_close_state *)private_data;
2526         uint32_t fid = (((uint32_t)(procid_to_pid(&e->pid))<<16) | e->share_file_id);
2527
2528         if (fid != state->r->in.fid) {
2529                 return; /* Not this file. */
2530         }
2531
2532         if (!process_exists(e->pid) ) {
2533                 return;
2534         }
2535
2536         /* Ok - send the close message. */
2537         DEBUG(10,("enum_file_close_fn: request to close file %s, %s\n",
2538                 sharepath,
2539                 share_mode_str(talloc_tos(), 0, e) ));
2540
2541         share_mode_entry_to_message(msg, e);
2542
2543         state->r->out.result = ntstatus_to_werror(
2544                 messaging_send_buf(state->msg_ctx,
2545                                 e->pid, MSG_SMB_CLOSE_FILE,
2546                                 (uint8 *)msg,
2547                                 MSG_SMB_SHARE_MODE_ENTRY_SIZE));
2548 }
2549
2550 /********************************************************************
2551  Close a file given a 32-bit file id.
2552 ********************************************************************/
2553
2554 WERROR _srvsvc_NetFileClose(struct pipes_struct *p,
2555                             struct srvsvc_NetFileClose *r)
2556 {
2557         struct enum_file_close_state state;
2558         bool is_disk_op;
2559
2560         DEBUG(5,("_srvsvc_NetFileClose: %d\n", __LINE__));
2561
2562         is_disk_op = security_token_has_privilege(p->session_info->security_token, SEC_PRIV_DISK_OPERATOR);
2563
2564         if (p->session_info->utok.uid != sec_initial_uid() && !is_disk_op) {
2565                 return WERR_ACCESS_DENIED;
2566         }
2567
2568         /* enum_file_close_fn sends the close message to
2569          * the relevent smbd process. */
2570
2571         r->out.result = WERR_BADFILE;
2572         state.r = r;
2573         state.msg_ctx = p->msg_ctx;
2574         share_mode_forall(enum_file_close_fn, &state);
2575         return r->out.result;
2576 }
2577
2578 /********************************************************************
2579 ********************************************************************/
2580
2581 WERROR _srvsvc_NetCharDevEnum(struct pipes_struct *p,
2582                               struct srvsvc_NetCharDevEnum *r)
2583 {
2584         p->rng_fault_state = True;
2585         return WERR_NOT_SUPPORTED;
2586 }
2587
2588 WERROR _srvsvc_NetCharDevGetInfo(struct pipes_struct *p,
2589                                  struct srvsvc_NetCharDevGetInfo *r)
2590 {
2591         p->rng_fault_state = True;
2592         return WERR_NOT_SUPPORTED;
2593 }
2594
2595 WERROR _srvsvc_NetCharDevControl(struct pipes_struct *p,
2596                                  struct srvsvc_NetCharDevControl *r)
2597 {
2598         p->rng_fault_state = True;
2599         return WERR_NOT_SUPPORTED;
2600 }
2601
2602 WERROR _srvsvc_NetCharDevQEnum(struct pipes_struct *p,
2603                                struct srvsvc_NetCharDevQEnum *r)
2604 {
2605         p->rng_fault_state = True;
2606         return WERR_NOT_SUPPORTED;
2607 }
2608
2609 WERROR _srvsvc_NetCharDevQGetInfo(struct pipes_struct *p,
2610                                   struct srvsvc_NetCharDevQGetInfo *r)
2611 {
2612         p->rng_fault_state = True;
2613         return WERR_NOT_SUPPORTED;
2614 }
2615
2616 WERROR _srvsvc_NetCharDevQSetInfo(struct pipes_struct *p,
2617                                   struct srvsvc_NetCharDevQSetInfo *r)
2618 {
2619         p->rng_fault_state = True;
2620         return WERR_NOT_SUPPORTED;
2621 }
2622
2623 WERROR _srvsvc_NetCharDevQPurge(struct pipes_struct *p,
2624                                 struct srvsvc_NetCharDevQPurge *r)
2625 {
2626         p->rng_fault_state = True;
2627         return WERR_NOT_SUPPORTED;
2628 }
2629
2630 WERROR _srvsvc_NetCharDevQPurgeSelf(struct pipes_struct *p,
2631                                     struct srvsvc_NetCharDevQPurgeSelf *r)
2632 {
2633         p->rng_fault_state = True;
2634         return WERR_NOT_SUPPORTED;
2635 }
2636
2637 WERROR _srvsvc_NetFileGetInfo(struct pipes_struct *p,
2638                               struct srvsvc_NetFileGetInfo *r)
2639 {
2640         p->rng_fault_state = True;
2641         return WERR_NOT_SUPPORTED;
2642 }
2643
2644 WERROR _srvsvc_NetShareCheck(struct pipes_struct *p,
2645                              struct srvsvc_NetShareCheck *r)
2646 {
2647         p->rng_fault_state = True;
2648         return WERR_NOT_SUPPORTED;
2649 }
2650
2651 WERROR _srvsvc_NetServerStatisticsGet(struct pipes_struct *p,
2652                                       struct srvsvc_NetServerStatisticsGet *r)
2653 {
2654         p->rng_fault_state = True;
2655         return WERR_NOT_SUPPORTED;
2656 }
2657
2658 WERROR _srvsvc_NetTransportAdd(struct pipes_struct *p,
2659                                struct srvsvc_NetTransportAdd *r)
2660 {
2661         p->rng_fault_state = True;
2662         return WERR_NOT_SUPPORTED;
2663 }
2664
2665 WERROR _srvsvc_NetTransportEnum(struct pipes_struct *p,
2666                                 struct srvsvc_NetTransportEnum *r)
2667 {
2668         p->rng_fault_state = True;
2669         return WERR_NOT_SUPPORTED;
2670 }
2671
2672 WERROR _srvsvc_NetTransportDel(struct pipes_struct *p,
2673                                struct srvsvc_NetTransportDel *r)
2674 {
2675         p->rng_fault_state = True;
2676         return WERR_NOT_SUPPORTED;
2677 }
2678
2679 WERROR _srvsvc_NetSetServiceBits(struct pipes_struct *p,
2680                                  struct srvsvc_NetSetServiceBits *r)
2681 {
2682         p->rng_fault_state = True;
2683         return WERR_NOT_SUPPORTED;
2684 }
2685
2686 WERROR _srvsvc_NetPathType(struct pipes_struct *p,
2687                            struct srvsvc_NetPathType *r)
2688 {
2689         p->rng_fault_state = True;
2690         return WERR_NOT_SUPPORTED;
2691 }
2692
2693 WERROR _srvsvc_NetPathCanonicalize(struct pipes_struct *p,
2694                                    struct srvsvc_NetPathCanonicalize *r)
2695 {
2696         p->rng_fault_state = True;
2697         return WERR_NOT_SUPPORTED;
2698 }
2699
2700 WERROR _srvsvc_NetPathCompare(struct pipes_struct *p,
2701                               struct srvsvc_NetPathCompare *r)
2702 {
2703         p->rng_fault_state = True;
2704         return WERR_NOT_SUPPORTED;
2705 }
2706
2707 WERROR _srvsvc_NETRPRNAMECANONICALIZE(struct pipes_struct *p,
2708                                       struct srvsvc_NETRPRNAMECANONICALIZE *r)
2709 {
2710         p->rng_fault_state = True;
2711         return WERR_NOT_SUPPORTED;
2712 }
2713
2714 WERROR _srvsvc_NetPRNameCompare(struct pipes_struct *p,
2715                                 struct srvsvc_NetPRNameCompare *r)
2716 {
2717         p->rng_fault_state = True;
2718         return WERR_NOT_SUPPORTED;
2719 }
2720
2721 WERROR _srvsvc_NetShareDelStart(struct pipes_struct *p,
2722                                 struct srvsvc_NetShareDelStart *r)
2723 {
2724         p->rng_fault_state = True;
2725         return WERR_NOT_SUPPORTED;
2726 }
2727
2728 WERROR _srvsvc_NetShareDelCommit(struct pipes_struct *p,
2729                                  struct srvsvc_NetShareDelCommit *r)
2730 {
2731         p->rng_fault_state = True;
2732         return WERR_NOT_SUPPORTED;
2733 }
2734
2735 WERROR _srvsvc_NetServerTransportAddEx(struct pipes_struct *p,
2736                                        struct srvsvc_NetServerTransportAddEx *r)
2737 {
2738         p->rng_fault_state = True;
2739         return WERR_NOT_SUPPORTED;
2740 }
2741
2742 WERROR _srvsvc_NetServerSetServiceBitsEx(struct pipes_struct *p,
2743                                          struct srvsvc_NetServerSetServiceBitsEx *r)
2744 {
2745         p->rng_fault_state = True;
2746         return WERR_NOT_SUPPORTED;
2747 }
2748
2749 WERROR _srvsvc_NETRDFSGETVERSION(struct pipes_struct *p,
2750                                  struct srvsvc_NETRDFSGETVERSION *r)
2751 {
2752         p->rng_fault_state = True;
2753         return WERR_NOT_SUPPORTED;
2754 }
2755
2756 WERROR _srvsvc_NETRDFSCREATELOCALPARTITION(struct pipes_struct *p,
2757                                            struct srvsvc_NETRDFSCREATELOCALPARTITION *r)
2758 {
2759         p->rng_fault_state = True;
2760         return WERR_NOT_SUPPORTED;
2761 }
2762
2763 WERROR _srvsvc_NETRDFSDELETELOCALPARTITION(struct pipes_struct *p,
2764                                            struct srvsvc_NETRDFSDELETELOCALPARTITION *r)
2765 {
2766         p->rng_fault_state = True;
2767         return WERR_NOT_SUPPORTED;
2768 }
2769
2770 WERROR _srvsvc_NETRDFSSETLOCALVOLUMESTATE(struct pipes_struct *p,
2771                                           struct srvsvc_NETRDFSSETLOCALVOLUMESTATE *r)
2772 {
2773         p->rng_fault_state = True;
2774         return WERR_NOT_SUPPORTED;
2775 }
2776
2777 WERROR _srvsvc_NETRDFSSETSERVERINFO(struct pipes_struct *p,
2778                                     struct srvsvc_NETRDFSSETSERVERINFO *r)
2779 {
2780         p->rng_fault_state = True;
2781         return WERR_NOT_SUPPORTED;
2782 }
2783
2784 WERROR _srvsvc_NETRDFSCREATEEXITPOINT(struct pipes_struct *p,
2785                                       struct srvsvc_NETRDFSCREATEEXITPOINT *r)
2786 {
2787         p->rng_fault_state = True;
2788         return WERR_NOT_SUPPORTED;
2789 }
2790
2791 WERROR _srvsvc_NETRDFSDELETEEXITPOINT(struct pipes_struct *p,
2792                                       struct srvsvc_NETRDFSDELETEEXITPOINT *r)
2793 {
2794         p->rng_fault_state = True;
2795         return WERR_NOT_SUPPORTED;
2796 }
2797
2798 WERROR _srvsvc_NETRDFSMODIFYPREFIX(struct pipes_struct *p,
2799                                    struct srvsvc_NETRDFSMODIFYPREFIX *r)
2800 {
2801         p->rng_fault_state = True;
2802         return WERR_NOT_SUPPORTED;
2803 }
2804
2805 WERROR _srvsvc_NETRDFSFIXLOCALVOLUME(struct pipes_struct *p,
2806                                      struct srvsvc_NETRDFSFIXLOCALVOLUME *r)
2807 {
2808         p->rng_fault_state = True;
2809         return WERR_NOT_SUPPORTED;
2810 }
2811
2812 WERROR _srvsvc_NETRDFSMANAGERREPORTSITEINFO(struct pipes_struct *p,
2813                                             struct srvsvc_NETRDFSMANAGERREPORTSITEINFO *r)
2814 {
2815         p->rng_fault_state = True;
2816         return WERR_NOT_SUPPORTED;
2817 }
2818
2819 WERROR _srvsvc_NETRSERVERTRANSPORTDELEX(struct pipes_struct *p,
2820                                         struct srvsvc_NETRSERVERTRANSPORTDELEX *r)
2821 {
2822         p->rng_fault_state = True;
2823         return WERR_NOT_SUPPORTED;
2824 }