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