Remove most of the remaining globals out of lib/util_sock.c.
[amitay/samba.git] / source3 / lib / substitute.c
1 /* 
2    Unix SMB/CIFS implementation.
3    string substitution functions
4    Copyright (C) Andrew Tridgell 1992-2000
5    Copyright (C) Gerald Carter   2006
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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
21
22 #include "includes.h"
23
24 extern struct current_user current_user;
25
26 fstring local_machine="";
27 fstring remote_arch="UNKNOWN";
28 userdom_struct current_user_info;
29 fstring remote_proto="UNKNOWN";
30
31 static fstring remote_machine;
32 static fstring smb_user_name;
33
34 /** 
35  * Set the 'local' machine name
36  * @param local_name the name we are being called
37  * @param if this is the 'final' name for us, not be be changed again
38  */
39
40 void set_local_machine_name(const char* local_name, bool perm)
41 {
42         static bool already_perm = False;
43         fstring tmp_local_machine;
44         char addr[INET6_ADDRSTRLEN];
45
46         fstrcpy(tmp_local_machine,local_name);
47         trim_char(tmp_local_machine,' ',' ');
48
49         /*
50          * Windows NT/2k uses "*SMBSERVER" and XP uses "*SMBSERV"
51          * arrggg!!! 
52          */
53
54         if ( strequal(tmp_local_machine, "*SMBSERVER") || strequal(tmp_local_machine, "*SMBSERV") )  {
55                 fstrcpy( local_machine,
56                         client_socket_addr(get_client_fd(), addr, sizeof(addr)) );
57                 return;
58         }
59
60         if (already_perm)
61                 return;
62
63         already_perm = perm;
64
65         alpha_strcpy(local_machine,tmp_local_machine,SAFE_NETBIOS_CHARS,sizeof(local_machine)-1);
66         strlower_m(local_machine);
67 }
68
69 /** 
70  * Set the 'remote' machine name
71  * @param remote_name the name our client wants to be called by
72  * @param if this is the 'final' name for them, not be be changed again
73  */
74
75 void set_remote_machine_name(const char* remote_name, bool perm)
76 {
77         static bool already_perm = False;
78         fstring tmp_remote_machine;
79
80         if (already_perm)
81                 return;
82
83         already_perm = perm;
84
85         fstrcpy(tmp_remote_machine,remote_name);
86         trim_char(tmp_remote_machine,' ',' ');
87         alpha_strcpy(remote_machine,tmp_remote_machine,SAFE_NETBIOS_CHARS,sizeof(remote_machine)-1);
88         strlower_m(remote_machine);
89 }
90
91 const char* get_remote_machine_name(void) 
92 {
93         return remote_machine;
94 }
95
96 const char* get_local_machine_name(void) 
97 {
98         if (!*local_machine) {
99                 return global_myname();
100         }
101
102         return local_machine;
103 }
104
105 /*******************************************************************
106  Setup the string used by %U substitution.
107 ********************************************************************/
108
109 void sub_set_smb_name(const char *name)
110 {
111         fstring tmp;
112         int len;
113         bool is_machine_account = False;
114
115         /* don't let anonymous logins override the name */
116         if (! *name)
117                 return;
118
119
120         fstrcpy( tmp, name );
121         trim_char( tmp, ' ', ' ' );
122         strlower_m( tmp );
123
124         len = strlen( tmp );
125
126         if ( len == 0 )
127                 return;
128
129         /* long story but here goes....we have to allow usernames
130            ending in '$' as they are valid machine account names.
131            So check for a machine account and re-add the '$'
132            at the end after the call to alpha_strcpy().   --jerry  */
133            
134         if ( tmp[len-1] == '$' )
135                 is_machine_account = True;
136         
137         alpha_strcpy( smb_user_name, tmp, SAFE_NETBIOS_CHARS, sizeof(smb_user_name)-1 );
138
139         if ( is_machine_account ) {
140                 len = strlen( smb_user_name );
141                 smb_user_name[len-1] = '$';
142         }
143 }
144
145 /*******************************************************************
146  Setup the strings used by substitutions. Called per packet. Ensure
147  %U name is set correctly also.
148 ********************************************************************/
149
150 void set_current_user_info(const userdom_struct *pcui)
151 {
152         current_user_info = *pcui;
153         /* The following is safe as current_user_info.smb_name
154          * has already been sanitised in register_existing_vuid. */
155         fstrcpy(smb_user_name, current_user_info.smb_name);
156 }
157
158 /*******************************************************************
159  return the current active user name
160 *******************************************************************/
161
162 const char* get_current_username( void )
163 {
164         if ( current_user_info.smb_name[0] == '\0' )
165                 return smb_user_name;
166
167         return current_user_info.smb_name; 
168 }
169
170 /*******************************************************************
171  Given a pointer to a %$(NAME) in p and the whole string in str
172  expand it as an environment variable.
173  Return a new allocated and expanded string.
174  Based on code by Branko Cibej <branko.cibej@hermes.si>
175  When this is called p points at the '%' character.
176  May substitute multiple occurrencies of the same env var.
177 ********************************************************************/
178
179 static char * realloc_expand_env_var(char *str, char *p)
180 {
181         char *envname;
182         char *envval;
183         char *q, *r;
184         int copylen;
185
186         if (p[0] != '%' || p[1] != '$' || p[2] != '(') {
187                 return str;
188         }
189
190         /*
191          * Look for the terminating ')'.
192          */
193
194         if ((q = strchr_m(p,')')) == NULL) {
195                 DEBUG(0,("expand_env_var: Unterminated environment variable [%s]\n", p));
196                 return str;
197         }
198
199         /*
200          * Extract the name from within the %$(NAME) string.
201          */
202
203         r = p + 3;
204         copylen = q - r;
205         
206         /* reserve space for use later add %$() chars */
207         if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) {
208                 return NULL;
209         }
210         
211         strncpy(envname,r,copylen);
212         envname[copylen] = '\0';
213
214         if ((envval = getenv(envname)) == NULL) {
215                 DEBUG(0,("expand_env_var: Environment variable [%s] not set\n", envname));
216                 SAFE_FREE(envname);
217                 return str;
218         }
219
220         /*
221          * Copy the full %$(NAME) into envname so it
222          * can be replaced.
223          */
224
225         copylen = q + 1 - p;
226         strncpy(envname,p,copylen);
227         envname[copylen] = '\0';
228         r = realloc_string_sub(str, envname, envval);
229         SAFE_FREE(envname);
230                 
231         return r;
232 }
233
234 /*******************************************************************
235 *******************************************************************/
236
237 static char *longvar_domainsid( void )
238 {
239         DOM_SID sid;
240         char *sid_string;
241         
242         if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) {
243                 return NULL;
244         }
245         
246         sid_string = SMB_STRDUP( sid_string_static( &sid ) );
247         
248         if ( !sid_string ) {
249                 DEBUG(0,("longvar_domainsid: failed to dup SID string!\n"));
250         }
251         
252         return sid_string;
253 }
254
255 /*******************************************************************
256 *******************************************************************/
257
258 struct api_longvar {
259         const char *name;
260         char* (*fn)( void );
261 };
262
263 static struct api_longvar longvar_table[] = {
264         { "DomainSID",          longvar_domainsid },
265         { NULL,                 NULL }
266 };
267
268 static char *get_longvar_val( const char *varname )
269 {
270         int i;
271         
272         DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname));
273         
274         for ( i=0; longvar_table[i].name; i++ ) {
275                 if ( strequal( longvar_table[i].name, varname ) ) {
276                         return longvar_table[i].fn();
277                 }
278         }
279         
280         return NULL;
281 }
282
283 /*******************************************************************
284  Expand the long smb.conf variable names given a pointer to a %(NAME).
285  Return the number of characters by which the pointer should be advanced.
286  When this is called p points at the '%' character.
287 ********************************************************************/
288
289 static char *realloc_expand_longvar(char *str, char *p)
290 {
291         fstring varname;
292         char *value;
293         char *q, *r;
294         int copylen;
295
296         if ( p[0] != '%' || p[1] != '(' ) {
297                 return str;
298         }
299
300         /* Look for the terminating ')'.*/
301
302         if ((q = strchr_m(p,')')) == NULL) {
303                 DEBUG(0,("realloc_expand_longvar: Unterminated environment variable [%s]\n", p));
304                 return str;
305         }
306
307         /* Extract the name from within the %(NAME) string.*/
308
309         r = p+2;
310         copylen = MIN( (q-r), (sizeof(varname)-1) );
311         strncpy(varname, r, copylen);
312         varname[copylen] = '\0';
313
314         if ((value = get_longvar_val(varname)) == NULL) {
315                 DEBUG(0,("realloc_expand_longvar: Variable [%s] not set.  Skipping\n", varname));
316                 return str;
317         }
318
319         /* Copy the full %(NAME) into envname so it can be replaced.*/
320
321         copylen = MIN( (q+1-p),(sizeof(varname)-1) );
322         strncpy( varname, p, copylen );
323         varname[copylen] = '\0';
324         r = realloc_string_sub(str, varname, value);
325         SAFE_FREE( value );
326         
327         /* skip over the %(varname) */
328         
329         return r;
330 }
331
332 /*******************************************************************
333  Patch from jkf@soton.ac.uk
334  Added this to implement %p (NIS auto-map version of %H)
335 *******************************************************************/
336
337 static char *automount_path(const char *user_name)
338 {
339         pstring server_path;
340
341         /* use the passwd entry as the default */
342         /* this will be the default if WITH_AUTOMOUNT is not used or fails */
343
344         pstrcpy(server_path, get_user_home_dir(user_name));
345
346 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
347
348         if (lp_nis_home_map()) {
349                 const char *home_path_start;
350                 const char *automount_value = automount_lookup(user_name);
351
352                 if(strlen(automount_value) > 0) {
353                         home_path_start = strchr_m(automount_value,':');
354                         if (home_path_start != NULL) {
355                                 DEBUG(5, ("NIS lookup succeeded.  Home path is: %s\n",
356                                                 home_path_start?(home_path_start+1):""));
357                                 pstrcpy(server_path, home_path_start+1);
358                         }
359                 } else {
360                         /* NIS key lookup failed: default to user home directory from password file */
361                         DEBUG(5, ("NIS lookup failed. Using Home path from passwd file. Home path is: %s\n", server_path ));
362                 }
363         }
364 #endif
365
366         DEBUG(4,("Home server path: %s\n", server_path));
367
368         return talloc_strdup(talloc_tos(), server_path);
369 }
370
371 /*******************************************************************
372  Patch from jkf@soton.ac.uk
373  This is Luke's original function with the NIS lookup code
374  moved out to a separate function.
375 *******************************************************************/
376
377 static const char *automount_server(const char *user_name)
378 {
379         pstring server_name;
380         const char *local_machine_name = get_local_machine_name(); 
381
382         /* use the local machine name as the default */
383         /* this will be the default if WITH_AUTOMOUNT is not used or fails */
384         if (local_machine_name && *local_machine_name)
385                 pstrcpy(server_name, local_machine_name);
386         else
387                 pstrcpy(server_name, global_myname());
388         
389 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
390
391         if (lp_nis_home_map()) {
392                 int home_server_len;
393                 char *automount_value = automount_lookup(user_name);
394                 home_server_len = strcspn(automount_value,":");
395                 DEBUG(5, ("NIS lookup succeeded.  Home server length: %d\n",home_server_len));
396                 if (home_server_len > sizeof(pstring))
397                         home_server_len = sizeof(pstring);
398                 strncpy(server_name, automount_value, home_server_len);
399                 server_name[home_server_len] = '\0';
400         }
401 #endif
402
403         DEBUG(4,("Home server: %s\n", server_name));
404
405         return talloc_strdup(talloc_tos(), server_name);
406 }
407
408 /****************************************************************************
409  Do some standard substitutions in a string.
410  len is the length in bytes of the space allowed in string str. If zero means
411  don't allow expansions.
412 ****************************************************************************/
413
414 void standard_sub_basic(const char *smb_name, const char *domain_name,
415                         char *str, size_t len)
416 {
417         char *s;
418         
419         if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) {
420                 strncpy( str, s, len );
421         }
422         
423         SAFE_FREE( s );
424         
425 }
426
427 /****************************************************************************
428  Do some standard substitutions in a string.
429  This function will return an allocated string that have to be freed.
430 ****************************************************************************/
431
432 char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name,
433                        const char *domain_name, const char *str)
434 {
435         char *a, *t;
436         
437         if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) {
438                 return NULL;
439         }
440         t = talloc_strdup(mem_ctx, a);
441         SAFE_FREE(a);
442         return t;
443 }
444
445 /****************************************************************************
446 ****************************************************************************/
447
448 char *alloc_sub_basic(const char *smb_name, const char *domain_name,
449                       const char *str)
450 {
451         char *b, *p, *s, *r, *a_string;
452         fstring pidstr, vnnstr;
453         struct passwd *pass;
454         char addr[INET6_ADDRSTRLEN];
455         const char *local_machine_name = get_local_machine_name();
456
457         /* workaround to prevent a crash while looking at bug #687 */
458         
459         if (!str) {
460                 DEBUG(0,("alloc_sub_basic: NULL source string!  This should not happen\n"));
461                 return NULL;
462         }
463         
464         a_string = SMB_STRDUP(str);
465         if (a_string == NULL) {
466                 DEBUG(0, ("alloc_sub_basic: Out of memory!\n"));
467                 return NULL;
468         }
469         
470         for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
471
472                 r = NULL;
473                 b = a_string;
474                 
475                 switch (*(p+1)) {
476                 case 'U' : 
477                         r = strdup_lower(smb_name);
478                         if (r == NULL) {
479                                 goto error;
480                         }
481                         a_string = realloc_string_sub(a_string, "%U", r);
482                         break;
483                 case 'G' :
484                         r = SMB_STRDUP(smb_name);
485                         if (r == NULL) {
486                                 goto error;
487                         }
488                         if ((pass = Get_Pwnam(r))!=NULL) {
489                                 a_string = realloc_string_sub(a_string, "%G", gidtoname(pass->pw_gid));
490                         } 
491                         break;
492                 case 'D' :
493                         r = strdup_upper(domain_name);
494                         if (r == NULL) {
495                                 goto error;
496                         }
497                         a_string = realloc_string_sub(a_string, "%D", r);
498                         break;
499                 case 'I' :
500                         a_string = realloc_string_sub(a_string, "%I",
501                                         client_addr(get_client_fd(),addr, sizeof(addr)));
502                         break;
503                 case 'i': 
504                         a_string = realloc_string_sub( a_string, "%i",
505                                         client_socket_addr(get_client_fd(), addr, sizeof(addr)) );
506                         break;
507                 case 'L' : 
508                         if ( StrnCaseCmp(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) {
509                                 break;
510                         }
511                         if (local_machine_name && *local_machine_name) {
512                                 a_string = realloc_string_sub(a_string, "%L", local_machine_name); 
513                         } else {
514                                 a_string = realloc_string_sub(a_string, "%L", global_myname()); 
515                         }
516                         break;
517                 case 'N':
518                         a_string = realloc_string_sub(a_string, "%N", automount_server(smb_name));
519                         break;
520                 case 'M' :
521                         a_string = realloc_string_sub(a_string, "%M", client_name(get_client_fd()));
522                         break;
523                 case 'R' :
524                         a_string = realloc_string_sub(a_string, "%R", remote_proto);
525                         break;
526                 case 'T' :
527                         a_string = realloc_string_sub(a_string, "%T", current_timestring(False));
528                         break;
529                 case 'a' :
530                         a_string = realloc_string_sub(a_string, "%a", remote_arch);
531                         break;
532                 case 'd' :
533                         slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid());
534                         a_string = realloc_string_sub(a_string, "%d", pidstr);
535                         break;
536                 case 'h' :
537                         a_string = realloc_string_sub(a_string, "%h", myhostname());
538                         break;
539                 case 'm' :
540                         a_string = realloc_string_sub(a_string, "%m", remote_machine);
541                         break;
542                 case 'v' :
543                         a_string = realloc_string_sub(a_string, "%v", SAMBA_VERSION_STRING);
544                         break;
545                 case 'w' :
546                         a_string = realloc_string_sub(a_string, "%w", lp_winbind_separator());
547                         break;
548                 case '$' :
549                         a_string = realloc_expand_env_var(a_string, p); /* Expand environment variables */
550                         break;
551                 case '(':
552                         a_string = realloc_expand_longvar( a_string, p );
553                         break;
554                 case 'V' :
555                         slprintf(vnnstr,sizeof(vnnstr)-1, "%u", get_my_vnn());
556                         a_string = realloc_string_sub(a_string, "%V", vnnstr);
557                         break;
558                 default: 
559                         break;
560                 }
561
562                 p++;
563                 SAFE_FREE(r);
564                 
565                 if ( !a_string ) {
566                         return NULL;
567                 }
568         }
569
570         return a_string;
571
572 error:
573         SAFE_FREE(a_string);
574         return NULL;
575 }
576
577 /****************************************************************************
578  Do some specific substitutions in a string.
579  This function will return an allocated string that have to be freed.
580 ****************************************************************************/
581
582 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
583                         const char *input_string,
584                         const char *username,
585                         const char *domain,
586                         uid_t uid,
587                         gid_t gid)
588 {
589         char *a_string;
590         char *ret_string = NULL;
591         char *b, *p, *s;
592         TALLOC_CTX *tmp_ctx;
593
594         if (!(tmp_ctx = talloc_new(mem_ctx))) {
595                 DEBUG(0, ("talloc_new failed\n"));
596                 return NULL;
597         }
598
599         a_string = talloc_strdup(tmp_ctx, input_string);
600         if (a_string == NULL) {
601                 DEBUG(0, ("talloc_sub_specified: Out of memory!\n"));
602                 goto done;
603         }
604         
605         for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
606                 
607                 b = a_string;
608                 
609                 switch (*(p+1)) {
610                 case 'U' : 
611                         a_string = talloc_string_sub(
612                                 tmp_ctx, a_string, "%U", username);
613                         break;
614                 case 'u' : 
615                         a_string = talloc_string_sub(
616                                 tmp_ctx, a_string, "%u", username);
617                         break;
618                 case 'G' :
619                         if (gid != -1) {
620                                 a_string = talloc_string_sub(
621                                         tmp_ctx, a_string, "%G",
622                                         gidtoname(gid));
623                         } else {
624                                 a_string = talloc_string_sub(
625                                         tmp_ctx, a_string,
626                                         "%G", "NO_GROUP");
627                         }
628                         break;
629                 case 'g' :
630                         if (gid != -1) {
631                                 a_string = talloc_string_sub(
632                                         tmp_ctx, a_string, "%g",
633                                         gidtoname(gid));
634                         } else {
635                                 a_string = talloc_string_sub(
636                                         tmp_ctx, a_string, "%g", "NO_GROUP");
637                         }
638                         break;
639                 case 'D' :
640                         a_string = talloc_string_sub(tmp_ctx, a_string,
641                                                      "%D", domain);
642                         break;
643                 case 'N' : 
644                         a_string = talloc_string_sub(
645                                 tmp_ctx, a_string, "%N",
646                                 automount_server(username)); 
647                         break;
648                 default: 
649                         break;
650                 }
651
652                 p++;
653                 if (a_string == NULL) {
654                         goto done;
655                 }
656         }
657
658         /* Watch out, using "mem_ctx" here, so all intermediate stuff goes
659          * away with the TALLOC_FREE(tmp_ctx) further down. */
660
661         ret_string = talloc_sub_basic(mem_ctx, username, domain, a_string);
662
663  done:
664         TALLOC_FREE(tmp_ctx);
665         return ret_string;
666 }
667
668 /****************************************************************************
669 ****************************************************************************/
670
671 static char *alloc_sub_advanced(const char *servicename, const char *user, 
672                          const char *connectpath, gid_t gid, 
673                          const char *smb_name, const char *domain_name,
674                          const char *str)
675 {
676         char *a_string, *ret_string;
677         char *b, *p, *s, *h;
678
679         a_string = SMB_STRDUP(str);
680         if (a_string == NULL) {
681                 DEBUG(0, ("alloc_sub_advanced: Out of memory!\n"));
682                 return NULL;
683         }
684         
685         for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
686                 
687                 b = a_string;
688                 
689                 switch (*(p+1)) {
690                 case 'N' :
691                         a_string = realloc_string_sub(a_string, "%N", automount_server(user));
692                         break;
693                 case 'H':
694                         if ((h = get_user_home_dir(user)))
695                                 a_string = realloc_string_sub(a_string, "%H", h);
696                         break;
697                 case 'P': 
698                         a_string = realloc_string_sub(a_string, "%P", connectpath); 
699                         break;
700                 case 'S': 
701                         a_string = realloc_string_sub(a_string, "%S", servicename);
702                         break;
703                 case 'g': 
704                         a_string = realloc_string_sub(a_string, "%g", gidtoname(gid)); 
705                         break;
706                 case 'u': 
707                         a_string = realloc_string_sub(a_string, "%u", user); 
708                         break;
709                         
710                         /* Patch from jkf@soton.ac.uk Left the %N (NIS
711                          * server name) in standard_sub_basic as it is
712                          * a feature for logon servers, hence uses the
713                          * username.  The %p (NIS server path) code is
714                          * here as it is used instead of the default
715                          * "path =" string in [homes] and so needs the
716                          * service name, not the username.  */
717                 case 'p': 
718                         a_string = realloc_string_sub(a_string, "%p",
719                                                       automount_path(servicename)); 
720                         break;
721                         
722                 default: 
723                         break;
724                 }
725
726                 p++;
727                 if (a_string == NULL) {
728                         return NULL;
729                 }
730         }
731
732         ret_string = alloc_sub_basic(smb_name, domain_name, a_string);
733         SAFE_FREE(a_string);
734         return ret_string;
735 }
736
737 /*
738  * This obviously is inefficient and needs to be merged into
739  * alloc_sub_advanced...
740  */
741
742 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
743                           const char *servicename, const char *user, 
744                           const char *connectpath, gid_t gid, 
745                           const char *smb_name, const char *domain_name,
746                           const char *str)
747 {
748         char *a, *t;
749
750         if (!(a = alloc_sub_advanced(servicename, user, connectpath, gid,
751                                      smb_name, domain_name, str))) {
752                 return NULL;
753         }
754         t = talloc_strdup(mem_ctx, a);
755         SAFE_FREE(a);
756         return t;
757 }
758
759
760 void standard_sub_advanced(const char *servicename, const char *user, 
761                            const char *connectpath, gid_t gid, 
762                            const char *smb_name, const char *domain_name,
763                            char *str, size_t len)
764 {
765         char *s;
766         
767         s = alloc_sub_advanced(servicename, user, connectpath,
768                                gid, smb_name, domain_name, str);
769
770         if ( s ) {
771                 strncpy( str, s, len );
772                 SAFE_FREE( s );
773         }
774 }
775
776 /****************************************************************************
777  *  Do some standard substitutions in a string.
778  *  ****************************************************************************/
779
780 void standard_sub_conn(connection_struct *conn, char *str, size_t len)
781 {
782         char *s;
783
784         s = alloc_sub_advanced(lp_servicename(SNUM(conn)), conn->user, conn->connectpath,
785                                conn->gid, smb_user_name, "", str);
786
787         if ( s ) {
788                 strncpy( str, s, len );
789                 SAFE_FREE( s );
790         }
791 }
792