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