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