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