Renamed vfs_init() to smbd_vfs_init() to allow vfs modules to compile.
[samba.git] / source3 / smbd / service.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    service (connection) opening and closing
5    Copyright (C) Andrew Tridgell 1992-1998
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 extern struct timeval smb_last_time;
25 extern int case_default;
26 extern BOOL case_preserve;
27 extern BOOL short_case_preserve;
28 extern BOOL case_mangle;
29 extern BOOL case_sensitive;
30 extern BOOL use_mangled_map;
31 extern fstring remote_machine;
32 extern userdom_struct current_user_info;
33 extern fstring remote_machine;
34
35
36 /****************************************************************************
37 load parameters specific to a connection/service
38 ****************************************************************************/
39 BOOL become_service(connection_struct *conn,BOOL do_chdir)
40 {
41         extern char magic_char;
42         static connection_struct *last_conn;
43         int snum;
44
45         if (!conn)  {
46                 last_conn = NULL;
47                 return(False);
48         }
49
50         conn->lastused = smb_last_time.tv_sec;
51
52         snum = SNUM(conn);
53   
54         if (do_chdir &&
55             vfs_ChDir(conn,conn->connectpath) != 0 &&
56             vfs_ChDir(conn,conn->origpath) != 0) {
57                 DEBUG(0,("chdir (%s) failed\n",
58                          conn->connectpath));
59                 return(False);
60         }
61
62         if (conn == last_conn)
63                 return(True);
64
65         last_conn = conn;
66
67         case_default = lp_defaultcase(snum);
68         case_preserve = lp_preservecase(snum);
69         short_case_preserve = lp_shortpreservecase(snum);
70         case_mangle = lp_casemangle(snum);
71         case_sensitive = lp_casesensitive(snum);
72         magic_char = lp_magicchar(snum);
73         use_mangled_map = (*lp_mangled_map(snum) ? True:False);
74         return(True);
75 }
76
77 /****************************************************************************
78  Add a home service. Returns the new service number or -1 if fail.
79 ****************************************************************************/
80
81 int add_home_service(char *service, char *homedir)
82 {
83         int iHomeService;
84         int iService;
85         fstring new_service;
86         char *usr_p = NULL;
87
88         if (!service || !homedir)
89                 return -1;
90
91         if ((iHomeService = lp_servicenumber(HOMES_NAME)) < 0)
92                 return -1;
93
94         /*
95          * If this is a winbindd provided username, remove
96          * the domain component before adding the service.
97          * Log a warning if the "path=" parameter does not
98          * include any macros.
99          */
100
101         fstrcpy(new_service, service);
102
103         if ((usr_p = strchr_m(service,*lp_winbind_separator())) != NULL)
104                 fstrcpy(new_service, usr_p+1);
105
106         lp_add_home(new_service,iHomeService,homedir);
107         iService = lp_servicenumber(new_service);
108
109         return iService;
110 }
111
112 /****************************************************************************
113  Find a service entry. service is always in dos codepage.
114 ****************************************************************************/
115
116 int find_service(char *service)
117 {
118    int iService;
119
120    all_string_sub(service,"\\","/",0);
121
122    iService = lp_servicenumber(service);
123
124    /* now handle the special case of a home directory */
125    if (iService < 0)
126    {
127       char *phome_dir = get_user_home_dir(service);
128
129       if(!phome_dir)
130       {
131         /*
132          * Try mapping the servicename, it may
133          * be a Windows to unix mapped user name.
134          */
135         if(map_username(service))
136           phome_dir = get_user_home_dir(service);
137       }
138
139       DEBUG(3,("checking for home directory %s gave %s\n",service,
140             phome_dir?phome_dir:"(NULL)"));
141
142       iService = add_home_service(service,phome_dir);
143    }
144
145    /* If we still don't have a service, attempt to add it as a printer. */
146    if (iService < 0)
147    {
148       int iPrinterService;
149
150       if ((iPrinterService = lp_servicenumber(PRINTERS_NAME)) >= 0)
151       {
152          char *pszTemp;
153
154          DEBUG(3,("checking whether %s is a valid printer name...\n", service));
155          pszTemp = PRINTCAP;
156          if ((pszTemp != NULL) && pcap_printername_ok(service, pszTemp))
157          {
158             DEBUG(3,("%s is a valid printer name\n", service));
159             DEBUG(3,("adding %s as a printer service\n", service));
160             lp_add_printer(service,iPrinterService);
161             iService = lp_servicenumber(service);
162             if (iService < 0)
163                DEBUG(0,("failed to add %s as a printer service!\n", service));
164          }
165          else
166             DEBUG(3,("%s is not a valid printer name\n", service));
167       }
168    }
169
170    /* Check for default vfs service?  Unsure whether to implement this */
171    if (iService < 0)
172    {
173    }
174
175    /* just possibly it's a default service? */
176    if (iService < 0) 
177    {
178      char *pdefservice = lp_defaultservice();
179      if (pdefservice && *pdefservice && 
180          !strequal(pdefservice,service) &&
181          !strstr(service,".."))
182      {
183        /*
184         * We need to do a local copy here as lp_defaultservice() 
185         * returns one of the rotating lp_string buffers that
186         * could get overwritten by the recursive find_service() call
187         * below. Fix from Josef Hinteregger <joehtg@joehtg.co.at>.
188         */
189        pstring defservice;
190        pstrcpy(defservice, pdefservice);
191        iService = find_service(defservice);
192        if (iService >= 0)
193        {
194          all_string_sub(service,"_","/",0);
195          iService = lp_add_service(service,iService);
196        }
197      }
198    }
199
200    if (iService >= 0)
201      if (!VALID_SNUM(iService))
202      {
203        DEBUG(0,("Invalid snum %d for %s\n",iService,service));
204        iService = -1;
205      }
206
207    if (iService < 0)
208      DEBUG(3,("find_service() failed to find service %s\n", service));
209
210    return (iService);
211 }
212
213
214 /****************************************************************************
215  do some basic sainity checks on the share.  
216  This function modifies dev, ecode.
217 ****************************************************************************/
218 static NTSTATUS share_sanity_checks(int snum, char* service, char *dev) 
219 {
220         
221         if (!lp_snum_ok(snum) || 
222             !check_access(smbd_server_fd(), 
223                           lp_hostsallow(snum), lp_hostsdeny(snum))) {    
224                 return NT_STATUS_ACCESS_DENIED;
225         }
226
227         /* you can only connect to the IPC$ service as an ipc device */
228         if (strequal(service,"IPC$") || strequal(service,"ADMIN$"))
229                 pstrcpy(dev,"IPC");
230         
231         if (*dev == '?' || !*dev) {
232                 if (lp_print_ok(snum)) {
233                         pstrcpy(dev,"LPT1:");
234                 } else {
235                         pstrcpy(dev,"A:");
236                 }
237         }
238
239         /* if the request is as a printer and you can't print then refuse */
240         strupper(dev);
241         if (!lp_print_ok(snum) && (strncmp(dev,"LPT",3) == 0)) {
242                 DEBUG(1,("Attempt to connect to non-printer as a printer\n"));
243                 return NT_STATUS_BAD_DEVICE_TYPE;
244         }
245
246         /* Behave as a printer if we are supposed to */
247         if (lp_print_ok(snum) && (strcmp(dev, "A:") == 0)) {
248                 pstrcpy(dev, "LPT1:");
249         }
250
251         return NT_STATUS_OK;
252 }
253
254
255 /****************************************************************************
256  readonly share?
257 ****************************************************************************/
258 static void set_read_only(connection_struct *conn) 
259 {
260         char **list;
261         char *service = lp_servicename(conn->service);
262         conn->read_only = lp_readonly(conn->service);
263
264         if (!service) return;
265
266         lp_list_copy(&list, lp_readlist(conn->service));
267         if (list) {
268                 if (!lp_list_substitute(list, "%S", service)) {
269                         DEBUG(0, ("ERROR: read list substitution failed\n"));
270                 }
271                 if (user_in_list(conn->user, list))
272                         conn->read_only = True;
273                 lp_list_free(&list);
274         }
275         
276         lp_list_copy(&list, lp_writelist(conn->service));
277         if (list) {
278                 if (!lp_list_substitute(list, "%S", service)) {
279                         DEBUG(0, ("ERROR: write list substitution failed\n"));
280                 }
281                 if (user_in_list(conn->user, list))
282                         conn->read_only = False;
283                 lp_list_free(&list);
284         }
285 }
286
287
288 /****************************************************************************
289   admin user check
290 ****************************************************************************/
291 static void set_admin_user(connection_struct *conn) 
292 {
293         /* admin user check */
294         
295         /* JRA - original code denied admin user if the share was
296            marked read_only. Changed as I don't think this is needed,
297            but old code left in case there is a problem here.
298         */
299         if (user_in_list(conn->user,lp_admin_users(conn->service)) 
300 #if 0
301             && !conn->read_only
302 #endif
303             ) {
304                 conn->admin_user = True;
305                 DEBUG(0,("%s logged in as admin user (root privileges)\n",conn->user));
306         } else {
307                 conn->admin_user = False;
308         }
309
310 #if 0 /* This done later, for now */    
311         /* admin users always run as uid=0 */
312         if (conn->admin_user) {
313                 conn->uid = 0;
314         }
315 #endif
316 }
317
318
319 /****************************************************************************
320   make a connection to a service
321 ****************************************************************************/
322 connection_struct *make_connection(char *service,char *password, 
323                                    int pwlen, char *dev,uint16 vuid, NTSTATUS *status)
324 {
325         int snum;
326         struct passwd *pass = NULL;
327         BOOL guest = False;
328         BOOL force = False;
329         connection_struct *conn;
330
331         fstring user;
332         ZERO_STRUCT(user);
333
334         strlower(service);
335
336         snum = find_service(service);
337
338         if (snum < 0) {
339                 if (strequal(service,"IPC$") || strequal(service,"ADMIN$")) {
340                         DEBUG(3,("refusing IPC connection\n"));
341                         *status = NT_STATUS_ACCESS_DENIED;
342                         return NULL;
343                 }
344
345                 DEBUG(0,("%s (%s) couldn't find service %s\n",
346                          remote_machine, client_addr(), service));
347                 *status = NT_STATUS_BAD_NETWORK_PATH;
348                 return NULL;
349         }
350
351         if (strequal(service,HOMES_NAME)) {
352                 if(lp_security() != SEC_SHARE) {
353                         if (validated_username(vuid)) {
354                                 fstring unix_username;
355                                 fstrcpy(unix_username,validated_username(vuid));
356                                 return(make_connection(unix_username,password,pwlen,dev,vuid,status));
357                         }
358                 } else {
359                         /* Security = share. Try with current_user_info.smb_name
360                          * as the username.  */
361                         if(*current_user_info.smb_name) {
362                                 fstring unix_username;
363                                 fstrcpy(unix_username,current_user_info.smb_name);
364                                 map_username(unix_username);
365                                 return(make_connection(unix_username,password,pwlen,dev,vuid,status));
366                         }
367                 }
368         }
369
370         if (NT_STATUS_IS_ERR(*status = share_sanity_checks(snum, service, dev))) {
371                 return NULL;
372         }       
373
374         /* add it as a possible user name if we 
375            are in share mode security */
376         if (lp_security() == SEC_SHARE) {
377                 add_session_user(service);
378         }
379
380
381         /* shall we let them in? */
382         if (!authorise_login(snum,user,password,pwlen,&guest,&force,vuid)) {
383                 DEBUG( 2, ( "Invalid username/password for %s [%s]\n", service, user ) );
384                 *status = NT_STATUS_WRONG_PASSWORD;
385                 return NULL;
386         }
387
388         add_session_user(user);
389   
390         conn = conn_new();
391         if (!conn) {
392                 DEBUG(0,("Couldn't find free connection.\n"));
393                 *status = NT_STATUS_INSUFFICIENT_RESOURCES;
394                 return NULL;
395         }
396
397         /* find out some info about the user */
398         pass = smb_getpwnam(user,True);
399
400         if (pass == NULL) {
401                 DEBUG(0,( "Couldn't find account %s\n",user));
402                 *status = NT_STATUS_NO_SUCH_USER;
403                 conn_free(conn);
404                 return NULL;
405         }
406
407         conn->force_user = force;
408         conn->vuid = vuid;
409         conn->uid = pass->pw_uid;
410         conn->gid = pass->pw_gid;
411         safe_strcpy(conn->client_address, client_addr(), 
412                     sizeof(conn->client_address)-1);
413         conn->num_files_open = 0;
414         conn->lastused = time(NULL);
415         conn->service = snum;
416         conn->used = True;
417         conn->printer = (strncmp(dev,"LPT",3) == 0);
418         conn->ipc = ((strncmp(dev,"IPC",3) == 0) || strequal(dev,"ADMIN$"));
419         conn->dirptr = NULL;
420         conn->veto_list = NULL;
421         conn->hide_list = NULL;
422         conn->veto_oplock_list = NULL;
423         string_set(&conn->dirpath,"");
424         string_set(&conn->user,user);
425         conn->nt_user_token = NULL;
426         
427         set_read_only(conn);
428         
429         set_admin_user(conn);
430
431         /*
432          * If force user is true, then store the
433          * given userid and also the primary groupid
434          * of the user we're forcing.
435          */
436         
437         if (*lp_force_user(snum)) {
438                 struct passwd *pass2;
439                 pstring fuser;
440                 pstrcpy(fuser,lp_force_user(snum));
441
442                 /* Allow %S to be used by force user. */
443                 pstring_sub(fuser,"%S",service);
444
445                 pass2 = (struct passwd *)Get_Pwnam(fuser,True);
446                 if (pass2) {
447                         conn->uid = pass2->pw_uid;
448                         conn->gid = pass2->pw_gid;
449                         string_set(&conn->user,fuser);
450                         fstrcpy(user,fuser);
451                         conn->force_user = True;
452                         DEBUG(3,("Forced user %s\n",fuser));      
453                 } else {
454                         DEBUG(1,("Couldn't find user %s\n",fuser));
455                 }
456         }
457
458         /* admin users always run as uid=0 */
459         if (conn->admin_user) {
460                 conn->uid = 0;
461         }
462
463 #ifdef HAVE_GETGRNAM 
464         /*
465          * If force group is true, then override
466          * any groupid stored for the connecting user.
467          */
468         
469         if (*lp_force_group(snum)) {
470                 gid_t gid;
471                 pstring gname;
472                 pstring tmp_gname;
473                 BOOL user_must_be_member = False;
474                 
475                 StrnCpy(tmp_gname,lp_force_group(snum),sizeof(pstring)-1);
476
477                 if (tmp_gname[0] == '+') {
478                         user_must_be_member = True;
479                         StrnCpy(gname,&tmp_gname[1],sizeof(pstring)-2);
480                 } else {
481                         StrnCpy(gname,tmp_gname,sizeof(pstring)-1);
482                 }
483                 /* default service may be a group name          */
484                 pstring_sub(gname,"%S",service);
485                 gid = nametogid(gname);
486                 
487                 if (gid != (gid_t)-1) {
488                         /*
489                          * If the user has been forced and the forced group starts
490                          * with a '+', then we only set the group to be the forced
491                          * group if the forced user is a member of that group.
492                          * Otherwise, the meaning of the '+' would be ignored.
493                          */
494                         if (conn->force_user && user_must_be_member) {
495                                 if (user_in_group_list( user, gname )) {
496                                                 conn->gid = gid;
497                                                 DEBUG(3,("Forced group %s for member %s\n",gname,user));
498                                 }
499                         } else {
500                                 conn->gid = gid;
501                                 DEBUG(3,("Forced group %s\n",gname));
502                         }
503                 } else {
504                         DEBUG(1,("Couldn't find group %s\n",gname));
505                 }
506         }
507 #endif /* HAVE_GETGRNAM */
508
509         {
510                 pstring s;
511                 pstrcpy(s,lp_pathname(snum));
512                 standard_sub_conn(conn,s);
513                 string_set(&conn->connectpath,s);
514                 DEBUG(3,("Connect path is %s\n",s));
515         }
516
517         /* groups stuff added by ih */
518         conn->ngroups = 0;
519         conn->groups = NULL;
520         
521         /* Find all the groups this uid is in and
522            store them. Used by become_user() */
523         initialise_groups(conn->user, conn->uid, conn->gid); 
524         get_current_groups(&conn->ngroups,&conn->groups);
525                 
526         conn->nt_user_token = create_nt_token(conn->uid, conn->gid, 
527                                               conn->ngroups, conn->groups,
528                                               guest);
529
530         /*
531          * New code to check if there's a share security descripter
532          * added from NT server manager. This is done after the
533          * smb.conf checks are done as we need a uid and token. JRA.
534          */
535
536         {
537                 BOOL can_write = share_access_check(conn, snum, vuid, FILE_WRITE_DATA);
538
539                 if (!can_write) {
540                         if (!share_access_check(conn, snum, vuid, FILE_READ_DATA)) {
541                                 /* No access, read or write. */
542                                 *status = NT_STATUS_ACCESS_DENIED;
543                                 DEBUG(0,( "make_connection: connection to %s denied due to security descriptor.\n",
544                                         service ));
545                                 conn_free(conn);
546                                 return NULL;
547                         } else {
548                                 conn->read_only = True;
549                         }
550                 }
551         }
552         /* Initialise VFS function pointers */
553
554         if (!smbd_vfs_init(conn)) {
555                 DEBUG(0, ("vfs_init failed for service %s\n", lp_servicename(SNUM(conn))));
556                 conn_free(conn);
557                 return NULL;
558         }
559
560         if (!become_user(conn, conn->vuid)) {
561                 /* No point continuing if they fail the basic checks */
562                 DEBUG(0,("Can't become connected user!\n"));
563                 conn_free(conn);
564                 *status = NT_STATUS_LOGON_FAILURE;
565                 return NULL;
566         }
567
568 /* ROOT Activities: */  
569         become_root();
570         /* check number of connections */
571         if (!claim_connection(conn,
572                               lp_servicename(SNUM(conn)),
573                               lp_max_connections(SNUM(conn)),
574                               False)) {
575                 DEBUG(1,("too many connections - rejected\n"));
576                 *status = NT_STATUS_INSUFFICIENT_RESOURCES;
577                 conn_free(conn);
578                 unbecome_root();
579                 unbecome_user();
580                 return NULL;
581         }  
582
583         /* Preexecs are done here as they might make the dir we are to ChDir to below */
584         /* execute any "root preexec = " line */
585         if (*lp_rootpreexec(SNUM(conn))) {
586                 int ret;
587                 pstring cmd;
588                 pstrcpy(cmd,lp_rootpreexec(SNUM(conn)));
589                 standard_sub_conn(conn,cmd);
590                 DEBUG(5,("cmd=%s\n",cmd));
591                 ret = smbrun(cmd,NULL);
592                 if (ret != 0 && lp_rootpreexec_close(SNUM(conn))) {
593                         DEBUG(1,("root preexec gave %d - failing connection\n", ret));
594                         yield_connection(conn,
595                                          lp_servicename(SNUM(conn)),
596                                          lp_max_connections(SNUM(conn)));
597                         conn_free(conn);
598                         *status = NT_STATUS_UNSUCCESSFUL;
599                         unbecome_root();
600                         unbecome_user();
601                         return NULL;
602                 }
603         }
604         unbecome_root();
605
606 /* USER Activites: */
607         /* Remember that a different vuid can connect later without these checks... */
608
609         /* Preexecs are done here as they might make the dir we are to ChDir to below */
610         /* execute any "preexec = " line */
611         if (*lp_preexec(SNUM(conn))) {
612                 int ret;
613                 pstring cmd;
614                 pstrcpy(cmd,lp_preexec(SNUM(conn)));
615                 standard_sub_conn(conn,cmd);
616                 ret = smbrun(cmd,NULL);
617                 if (ret != 0 && lp_preexec_close(SNUM(conn))) {
618                         DEBUG(1,("preexec gave %d - failing connection\n", ret));
619                         unbecome_user();
620                         yield_connection(conn, lp_servicename(SNUM(conn)), lp_max_connections(SNUM(conn)));
621                         conn_free(conn);
622                         *status = NT_STATUS_UNSUCCESSFUL;
623                         return NULL;
624                 }
625         }
626
627         if (vfs_ChDir(conn,conn->connectpath) != 0) {
628                 DEBUG(0,("%s (%s) Can't change directory to %s (%s)\n",
629                          remote_machine, conn->client_address,
630                          conn->connectpath,strerror(errno)));
631                 unbecome_user();
632                 yield_connection(conn,
633                                  lp_servicename(SNUM(conn)),
634                                  lp_max_connections(SNUM(conn)));
635                 conn_free(conn);
636                 *status = NT_STATUS_BAD_NETWORK_NAME;
637                 return NULL;
638         }
639         
640         string_set(&conn->origpath,conn->connectpath);
641         
642 #if SOFTLINK_OPTIMISATION
643         /* resolve any soft links early */
644         {
645                 pstring s;
646                 pstrcpy(s,conn->connectpath);
647                 vfs_GetWd(conn,s);
648                 string_set(&conn->connectpath,s);
649                 vfs_ChDir(conn,conn->connectpath);
650         }
651 #endif
652         
653         /*
654          * Print out the 'connected as' stuff here as we need
655          * to know the effective uid and gid we will be using
656          * (at least initially).
657          */
658
659         if( DEBUGLVL( IS_IPC(conn) ? 3 : 1 ) ) {
660                 dbgtext( "%s (%s) ", remote_machine, conn->client_address );
661                 dbgtext( "connect to service %s ", lp_servicename(SNUM(conn)) );
662                 dbgtext( "initially as user %s ", user );
663                 dbgtext( "(uid=%d, gid=%d) ", (int)geteuid(), (int)getegid() );
664                 dbgtext( "(pid %d)\n", (int)sys_getpid() );
665         }
666         
667         /* Add veto/hide lists */
668         if (!IS_IPC(conn) && !IS_PRINT(conn)) {
669                 set_namearray( &conn->veto_list, lp_veto_files(SNUM(conn)));
670                 set_namearray( &conn->hide_list, lp_hide_files(SNUM(conn)));
671                 set_namearray( &conn->veto_oplock_list, lp_veto_oplocks(SNUM(conn)));
672         }
673         
674         /* Invoke VFS make connection hook */
675
676         if (conn->vfs_ops.connect) {
677                 if (conn->vfs_ops.connect(conn, service, user) < 0) {
678                         DEBUG(0,("make_connection: VFS make connection failed!\n"));
679                         *status = NT_STATUS_UNSUCCESSFUL;
680                         unbecome_user();
681                         conn_free(conn);
682                         return NULL;
683                 }
684         }
685
686         /* we've finished with the sensitive stuff */
687         unbecome_user();
688             
689         return(conn);
690 }
691
692
693 /****************************************************************************
694 close a cnum
695 ****************************************************************************/
696 void close_cnum(connection_struct *conn, uint16 vuid)
697 {
698         DirCacheFlush(SNUM(conn));
699
700         unbecome_user();
701
702         DEBUG(IS_IPC(conn)?3:1, ("%s (%s) closed connection to service %s\n",
703                                  remote_machine,conn->client_address,
704                                  lp_servicename(SNUM(conn))));
705
706         if (conn->vfs_ops.disconnect != NULL) {
707
708             /* Call VFS disconnect hook */
709             
710             conn->vfs_ops.disconnect(conn);
711             
712         }
713
714         yield_connection(conn,
715                          lp_servicename(SNUM(conn)),
716                          lp_max_connections(SNUM(conn)));
717
718         file_close_conn(conn);
719         dptr_closecnum(conn);
720
721         /* execute any "postexec = " line */
722         if (*lp_postexec(SNUM(conn)) && 
723             become_user(conn, vuid))  {
724                 pstring cmd;
725                 pstrcpy(cmd,lp_postexec(SNUM(conn)));
726                 standard_sub_conn(conn,cmd);
727                 smbrun(cmd,NULL);
728                 unbecome_user();
729         }
730
731         unbecome_user();
732         /* execute any "root postexec = " line */
733         if (*lp_rootpostexec(SNUM(conn)))  {
734                 pstring cmd;
735                 pstrcpy(cmd,lp_rootpostexec(SNUM(conn)));
736                 standard_sub_conn(conn,cmd);
737                 smbrun(cmd,NULL);
738         }
739         conn_free(conn);
740 }