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