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