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