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