selftest split $PERL into multiple arguments for Test::More check
[Samba.git] / source3 / lib / substitute.c
blob399ef1daa3be603984b0aefaa602d72457b4d209
1 /*
2 Unix SMB/CIFS implementation.
3 string substitution functions
4 Copyright (C) Andrew Tridgell 1992-2000
5 Copyright (C) Gerald Carter 2006
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.
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.
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/>.
22 #include "includes.h"
23 #include "secrets.h"
25 static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
26 const char *str);
28 userdom_struct current_user_info;
29 fstring remote_proto="UNKNOWN";
31 /**
32 * Set the 'local' machine name
33 * @param local_name the name we are being called
34 * @param if this is the 'final' name for us, not be be changed again
37 static char *local_machine;
39 void free_local_machine_name(void)
41 SAFE_FREE(local_machine);
44 bool set_local_machine_name(const char *local_name, bool perm)
46 static bool already_perm = false;
47 char *tmp_local_machine = NULL;
48 size_t len;
50 if (already_perm) {
51 return true;
54 tmp_local_machine = SMB_STRDUP(local_name);
55 if (!tmp_local_machine) {
56 return false;
58 trim_char(tmp_local_machine,' ',' ');
60 SAFE_FREE(local_machine);
61 len = strlen(tmp_local_machine);
62 local_machine = SMB_CALLOC_ARRAY(char, len+1);
63 if (!local_machine) {
64 SAFE_FREE(tmp_local_machine);
65 return false;
67 /* alpha_strcpy includes the space for the terminating nul. */
68 alpha_strcpy(local_machine,tmp_local_machine,
69 SAFE_NETBIOS_CHARS,len+1);
70 strlower_m(local_machine);
71 SAFE_FREE(tmp_local_machine);
73 already_perm = perm;
75 return true;
78 const char *get_local_machine_name(void)
80 if (!local_machine || !*local_machine) {
81 return global_myname();
84 return local_machine;
87 /**
88 * Set the 'remote' machine name
89 * @param remote_name the name our client wants to be called by
90 * @param if this is the 'final' name for them, not be be changed again
93 static char *remote_machine;
95 bool set_remote_machine_name(const char *remote_name, bool perm)
97 static bool already_perm = False;
98 char *tmp_remote_machine;
99 size_t len;
101 if (already_perm) {
102 return true;
105 tmp_remote_machine = SMB_STRDUP(remote_name);
106 if (!tmp_remote_machine) {
107 return false;
109 trim_char(tmp_remote_machine,' ',' ');
111 SAFE_FREE(remote_machine);
112 len = strlen(tmp_remote_machine);
113 remote_machine = SMB_CALLOC_ARRAY(char, len+1);
114 if (!remote_machine) {
115 SAFE_FREE(tmp_remote_machine);
116 return false;
119 /* alpha_strcpy includes the space for the terminating nul. */
120 alpha_strcpy(remote_machine,tmp_remote_machine,
121 SAFE_NETBIOS_CHARS,len+1);
122 strlower_m(remote_machine);
123 SAFE_FREE(tmp_remote_machine);
125 already_perm = perm;
127 return true;
130 const char *get_remote_machine_name(void)
132 return remote_machine ? remote_machine : "";
135 /*******************************************************************
136 Setup the string used by %U substitution.
137 ********************************************************************/
139 static char *smb_user_name;
141 void sub_set_smb_name(const char *name)
143 char *tmp;
144 size_t len;
145 bool is_machine_account = false;
147 /* don't let anonymous logins override the name */
148 if (!name || !*name) {
149 return;
152 tmp = SMB_STRDUP(name);
153 if (!tmp) {
154 return;
156 trim_char(tmp, ' ', ' ');
157 strlower_m(tmp);
159 len = strlen(tmp);
161 if (len == 0) {
162 SAFE_FREE(tmp);
163 return;
166 /* long story but here goes....we have to allow usernames
167 ending in '$' as they are valid machine account names.
168 So check for a machine account and re-add the '$'
169 at the end after the call to alpha_strcpy(). --jerry */
171 if (tmp[len-1] == '$') {
172 is_machine_account = True;
175 SAFE_FREE(smb_user_name);
176 smb_user_name = SMB_CALLOC_ARRAY(char, len+1);
177 if (!smb_user_name) {
178 SAFE_FREE(tmp);
179 return;
182 /* alpha_strcpy includes the space for the terminating nul. */
183 alpha_strcpy(smb_user_name, tmp,
184 SAFE_NETBIOS_CHARS,
185 len+1);
187 SAFE_FREE(tmp);
189 if (is_machine_account) {
190 len = strlen(smb_user_name);
191 smb_user_name[len-1] = '$';
195 static char sub_peeraddr[INET6_ADDRSTRLEN];
196 static const char *sub_peername = "";
197 static char sub_sockaddr[INET6_ADDRSTRLEN];
199 void sub_set_socket_ids(const char *peeraddr, const char *peername,
200 const char *sockaddr)
202 const char *addr = peeraddr;
204 if (strnequal(addr, "::ffff:", 7)) {
205 addr += 7;
207 strlcpy(sub_peeraddr, addr, sizeof(sub_peeraddr));
209 sub_peername = SMB_STRDUP(peername);
210 if (sub_peername == NULL) {
211 sub_peername = sub_peeraddr;
215 * Shouldn't we do the ::ffff: cancellation here as well? The
216 * original code in alloc_sub_basic() did not do it, so I'm
217 * leaving it out here as well for compatibility.
219 strlcpy(sub_sockaddr, sockaddr, sizeof(sub_sockaddr));
222 static const char *get_smb_user_name(void)
224 return smb_user_name ? smb_user_name : "";
227 /*******************************************************************
228 Setup the strings used by substitutions. Called per packet. Ensure
229 %U name is set correctly also.
231 smb_name must be sanitized by alpha_strcpy
232 ********************************************************************/
234 void set_current_user_info(const char *smb_name, const char *unix_name,
235 const char *domain)
237 fstrcpy(current_user_info.smb_name, smb_name);
238 fstrcpy(current_user_info.unix_name, unix_name);
239 fstrcpy(current_user_info.domain, domain);
241 /* The following is safe as current_user_info.smb_name
242 * has already been sanitised in register_existing_vuid. */
244 sub_set_smb_name(current_user_info.smb_name);
247 /*******************************************************************
248 Return the current active user name.
249 *******************************************************************/
251 const char *get_current_username(void)
253 if (current_user_info.smb_name[0] == '\0' ) {
254 return get_smb_user_name();
257 return current_user_info.smb_name;
260 /*******************************************************************
261 Given a pointer to a %$(NAME) in p and the whole string in str
262 expand it as an environment variable.
263 Return a new allocated and expanded string.
264 Based on code by Branko Cibej <branko.cibej@hermes.si>
265 When this is called p points at the '%' character.
266 May substitute multiple occurrencies of the same env var.
267 ********************************************************************/
269 static char * realloc_expand_env_var(char *str, char *p)
271 char *envname;
272 char *envval;
273 char *q, *r;
274 int copylen;
276 if (p[0] != '%' || p[1] != '$' || p[2] != '(') {
277 return str;
281 * Look for the terminating ')'.
284 if ((q = strchr_m(p,')')) == NULL) {
285 DEBUG(0,("expand_env_var: Unterminated environment variable [%s]\n", p));
286 return str;
290 * Extract the name from within the %$(NAME) string.
293 r = p + 3;
294 copylen = q - r;
296 /* reserve space for use later add %$() chars */
297 if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) {
298 return NULL;
301 strncpy(envname,r,copylen);
302 envname[copylen] = '\0';
304 if ((envval = getenv(envname)) == NULL) {
305 DEBUG(0,("expand_env_var: Environment variable [%s] not set\n", envname));
306 SAFE_FREE(envname);
307 return str;
311 * Copy the full %$(NAME) into envname so it
312 * can be replaced.
315 copylen = q + 1 - p;
316 strncpy(envname,p,copylen);
317 envname[copylen] = '\0';
318 r = realloc_string_sub(str, envname, envval);
319 SAFE_FREE(envname);
321 return r;
324 /*******************************************************************
325 *******************************************************************/
327 static char *longvar_domainsid( void )
329 struct dom_sid sid;
330 fstring tmp;
331 char *sid_string;
333 if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) {
334 return NULL;
337 sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) );
339 if ( !sid_string ) {
340 DEBUG(0,("longvar_domainsid: failed to dup SID string!\n"));
343 return sid_string;
346 /*******************************************************************
347 *******************************************************************/
349 struct api_longvar {
350 const char *name;
351 char* (*fn)( void );
354 static struct api_longvar longvar_table[] = {
355 { "DomainSID", longvar_domainsid },
356 { NULL, NULL }
359 static char *get_longvar_val( const char *varname )
361 int i;
363 DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname));
365 for ( i=0; longvar_table[i].name; i++ ) {
366 if ( strequal( longvar_table[i].name, varname ) ) {
367 return longvar_table[i].fn();
371 return NULL;
374 /*******************************************************************
375 Expand the long smb.conf variable names given a pointer to a %(NAME).
376 Return the number of characters by which the pointer should be advanced.
377 When this is called p points at the '%' character.
378 ********************************************************************/
380 static char *realloc_expand_longvar(char *str, char *p)
382 fstring varname;
383 char *value;
384 char *q, *r;
385 int copylen;
387 if ( p[0] != '%' || p[1] != '(' ) {
388 return str;
391 /* Look for the terminating ')'.*/
393 if ((q = strchr_m(p,')')) == NULL) {
394 DEBUG(0,("realloc_expand_longvar: Unterminated environment variable [%s]\n", p));
395 return str;
398 /* Extract the name from within the %(NAME) string.*/
400 r = p+2;
401 copylen = MIN( (q-r), (sizeof(varname)-1) );
402 strncpy(varname, r, copylen);
403 varname[copylen] = '\0';
405 if ((value = get_longvar_val(varname)) == NULL) {
406 DEBUG(0,("realloc_expand_longvar: Variable [%s] not set. Skipping\n", varname));
407 return str;
410 /* Copy the full %(NAME) into envname so it can be replaced.*/
412 copylen = MIN( (q+1-p),(sizeof(varname)-1) );
413 strncpy( varname, p, copylen );
414 varname[copylen] = '\0';
415 r = realloc_string_sub(str, varname, value);
416 SAFE_FREE( value );
418 /* skip over the %(varname) */
420 return r;
423 /*******************************************************************
424 Patch from jkf@soton.ac.uk
425 Added this to implement %p (NIS auto-map version of %H)
426 *******************************************************************/
428 static const char *automount_path(const char *user_name)
430 TALLOC_CTX *ctx = talloc_tos();
431 const char *server_path;
433 /* use the passwd entry as the default */
434 /* this will be the default if WITH_AUTOMOUNT is not used or fails */
436 server_path = talloc_strdup(ctx, get_user_home_dir(ctx, user_name));
437 if (!server_path) {
438 return "";
441 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
443 if (lp_nis_home_map()) {
444 const char *home_path_start;
445 char *automount_value = automount_lookup(ctx, user_name);
447 if(automount_value && strlen(automount_value) > 0) {
448 home_path_start = strchr_m(automount_value,':');
449 if (home_path_start != NULL) {
450 DEBUG(5, ("NIS lookup succeeded. "
451 "Home path is: %s\n",
452 home_path_start ?
453 (home_path_start+1):""));
454 server_path = talloc_strdup(ctx,
455 home_path_start+1);
456 if (!server_path) {
457 server_path = "";
460 } else {
461 /* NIS key lookup failed: default to
462 * user home directory from password file */
463 DEBUG(5, ("NIS lookup failed. Using Home path from "
464 "passwd file. Home path is: %s\n", server_path ));
467 #endif
469 DEBUG(4,("Home server path: %s\n", server_path));
470 return server_path;
473 /*******************************************************************
474 Patch from jkf@soton.ac.uk
475 This is Luke's original function with the NIS lookup code
476 moved out to a separate function.
477 *******************************************************************/
479 static const char *automount_server(const char *user_name)
481 TALLOC_CTX *ctx = talloc_tos();
482 const char *server_name;
483 const char *local_machine_name = get_local_machine_name();
485 /* use the local machine name as the default */
486 /* this will be the default if WITH_AUTOMOUNT is not used or fails */
487 if (local_machine_name && *local_machine_name) {
488 server_name = talloc_strdup(ctx, local_machine_name);
489 } else {
490 server_name = talloc_strdup(ctx, global_myname());
493 if (!server_name) {
494 return "";
497 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
498 if (lp_nis_home_map()) {
499 char *p;
500 char *srv;
501 char *automount_value = automount_lookup(ctx, user_name);
502 if (!automount_value) {
503 return "";
505 srv = talloc_strdup(ctx, automount_value);
506 if (!srv) {
507 return "";
509 p = strchr_m(srv, ':');
510 if (!p) {
511 return "";
513 *p = '\0';
514 server_name = srv;
515 DEBUG(5, ("NIS lookup succeeded. Home server %s\n",
516 server_name));
518 #endif
520 DEBUG(4,("Home server: %s\n", server_name));
521 return server_name;
524 /****************************************************************************
525 Do some standard substitutions in a string.
526 len is the length in bytes of the space allowed in string str. If zero means
527 don't allow expansions.
528 ****************************************************************************/
530 void standard_sub_basic(const char *smb_name, const char *domain_name,
531 char *str, size_t len)
533 char *s;
535 if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) {
536 strncpy( str, s, len );
539 SAFE_FREE( s );
542 /****************************************************************************
543 Do some standard substitutions in a string.
544 This function will return an allocated string that have to be freed.
545 ****************************************************************************/
547 char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name,
548 const char *domain_name, const char *str)
550 char *a, *t;
552 if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) {
553 return NULL;
555 t = talloc_strdup(mem_ctx, a);
556 SAFE_FREE(a);
557 return t;
560 /****************************************************************************
561 ****************************************************************************/
563 static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
564 const char *str)
566 char *b, *p, *s, *r, *a_string;
567 fstring pidstr, vnnstr;
568 const char *local_machine_name = get_local_machine_name();
569 TALLOC_CTX *tmp_ctx = NULL;
571 /* workaround to prevent a crash while looking at bug #687 */
573 if (!str) {
574 DEBUG(0,("alloc_sub_basic: NULL source string! This should not happen\n"));
575 return NULL;
578 a_string = SMB_STRDUP(str);
579 if (a_string == NULL) {
580 DEBUG(0, ("alloc_sub_basic: Out of memory!\n"));
581 return NULL;
584 tmp_ctx = talloc_stackframe();
586 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
588 r = NULL;
589 b = a_string;
591 switch (*(p+1)) {
592 case 'U' :
593 r = strlower_talloc(tmp_ctx, smb_name);
594 if (r == NULL) {
595 goto error;
597 a_string = realloc_string_sub(a_string, "%U", r);
598 break;
599 case 'G' : {
600 struct passwd *pass;
601 r = talloc_strdup(tmp_ctx, smb_name);
602 if (r == NULL) {
603 goto error;
605 pass = Get_Pwnam_alloc(tmp_ctx, r);
606 if (pass != NULL) {
607 a_string = realloc_string_sub(
608 a_string, "%G",
609 gidtoname(pass->pw_gid));
611 TALLOC_FREE(pass);
612 break;
614 case 'D' :
615 r = strupper_talloc(tmp_ctx, domain_name);
616 if (r == NULL) {
617 goto error;
619 a_string = realloc_string_sub(a_string, "%D", r);
620 break;
621 case 'I' : {
622 a_string = realloc_string_sub(
623 a_string, "%I",
624 sub_peeraddr[0] ? sub_peeraddr : "0.0.0.0");
625 break;
627 case 'i':
628 a_string = realloc_string_sub(
629 a_string, "%i",
630 sub_sockaddr[0] ? sub_sockaddr : "0.0.0.0");
631 break;
632 case 'L' :
633 if ( StrnCaseCmp(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) {
634 break;
636 if (local_machine_name && *local_machine_name) {
637 a_string = realloc_string_sub(a_string, "%L", local_machine_name);
638 } else {
639 a_string = realloc_string_sub(a_string, "%L", global_myname());
641 break;
642 case 'N':
643 a_string = realloc_string_sub(a_string, "%N", automount_server(smb_name));
644 break;
645 case 'M' :
646 a_string = realloc_string_sub(a_string, "%M",
647 sub_peername);
648 break;
649 case 'R' :
650 a_string = realloc_string_sub(a_string, "%R", remote_proto);
651 break;
652 case 'T' :
653 a_string = realloc_string_sub(a_string, "%T", current_timestring(tmp_ctx, False));
654 break;
655 case 'a' :
656 a_string = realloc_string_sub(a_string, "%a",
657 get_remote_arch_str());
658 break;
659 case 'd' :
660 slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid());
661 a_string = realloc_string_sub(a_string, "%d", pidstr);
662 break;
663 case 'h' :
664 a_string = realloc_string_sub(a_string, "%h", myhostname());
665 break;
666 case 'm' :
667 a_string = realloc_string_sub(a_string, "%m",
668 remote_machine
669 ? remote_machine
670 : "");
671 break;
672 case 'v' :
673 a_string = realloc_string_sub(a_string, "%v", samba_version_string());
674 break;
675 case 'w' :
676 a_string = realloc_string_sub(a_string, "%w", lp_winbind_separator());
677 break;
678 case '$' :
679 a_string = realloc_expand_env_var(a_string, p); /* Expand environment variables */
680 break;
681 case '(':
682 a_string = realloc_expand_longvar( a_string, p );
683 break;
684 case 'V' :
685 slprintf(vnnstr,sizeof(vnnstr)-1, "%u", get_my_vnn());
686 a_string = realloc_string_sub(a_string, "%V", vnnstr);
687 break;
688 default:
689 break;
692 p++;
693 TALLOC_FREE(r);
695 if (a_string == NULL) {
696 goto done;
700 goto done;
702 error:
703 SAFE_FREE(a_string);
705 done:
706 TALLOC_FREE(tmp_ctx);
707 return a_string;
710 /****************************************************************************
711 Do some specific substitutions in a string.
712 This function will return an allocated string that have to be freed.
713 ****************************************************************************/
715 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
716 const char *input_string,
717 const char *username,
718 const char *domain,
719 uid_t uid,
720 gid_t gid)
722 char *a_string;
723 char *ret_string = NULL;
724 char *b, *p, *s;
725 TALLOC_CTX *tmp_ctx;
727 if (!(tmp_ctx = talloc_new(mem_ctx))) {
728 DEBUG(0, ("talloc_new failed\n"));
729 return NULL;
732 a_string = talloc_strdup(tmp_ctx, input_string);
733 if (a_string == NULL) {
734 DEBUG(0, ("talloc_sub_specified: Out of memory!\n"));
735 goto done;
738 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
740 b = a_string;
742 switch (*(p+1)) {
743 case 'U' :
744 a_string = talloc_string_sub(
745 tmp_ctx, a_string, "%U", username);
746 break;
747 case 'u' :
748 a_string = talloc_string_sub(
749 tmp_ctx, a_string, "%u", username);
750 break;
751 case 'G' :
752 if (gid != -1) {
753 a_string = talloc_string_sub(
754 tmp_ctx, a_string, "%G",
755 gidtoname(gid));
756 } else {
757 a_string = talloc_string_sub(
758 tmp_ctx, a_string,
759 "%G", "NO_GROUP");
761 break;
762 case 'g' :
763 if (gid != -1) {
764 a_string = talloc_string_sub(
765 tmp_ctx, a_string, "%g",
766 gidtoname(gid));
767 } else {
768 a_string = talloc_string_sub(
769 tmp_ctx, a_string, "%g", "NO_GROUP");
771 break;
772 case 'D' :
773 a_string = talloc_string_sub(tmp_ctx, a_string,
774 "%D", domain);
775 break;
776 case 'N' :
777 a_string = talloc_string_sub(
778 tmp_ctx, a_string, "%N",
779 automount_server(username));
780 break;
781 default:
782 break;
785 p++;
786 if (a_string == NULL) {
787 goto done;
791 /* Watch out, using "mem_ctx" here, so all intermediate stuff goes
792 * away with the TALLOC_FREE(tmp_ctx) further down. */
794 ret_string = talloc_sub_basic(mem_ctx, username, domain, a_string);
796 done:
797 TALLOC_FREE(tmp_ctx);
798 return ret_string;
801 /****************************************************************************
802 ****************************************************************************/
804 static char *alloc_sub_advanced(const char *servicename, const char *user,
805 const char *connectpath, gid_t gid,
806 const char *smb_name, const char *domain_name,
807 const char *str)
809 char *a_string, *ret_string;
810 char *b, *p, *s;
812 a_string = SMB_STRDUP(str);
813 if (a_string == NULL) {
814 DEBUG(0, ("alloc_sub_advanced: Out of memory!\n"));
815 return NULL;
818 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
820 b = a_string;
822 switch (*(p+1)) {
823 case 'N' :
824 a_string = realloc_string_sub(a_string, "%N", automount_server(user));
825 break;
826 case 'H': {
827 char *h;
828 if ((h = get_user_home_dir(talloc_tos(), user)))
829 a_string = realloc_string_sub(a_string, "%H", h);
830 TALLOC_FREE(h);
831 break;
833 case 'P':
834 a_string = realloc_string_sub(a_string, "%P", connectpath);
835 break;
836 case 'S':
837 a_string = realloc_string_sub(a_string, "%S", servicename);
838 break;
839 case 'g':
840 a_string = realloc_string_sub(a_string, "%g", gidtoname(gid));
841 break;
842 case 'u':
843 a_string = realloc_string_sub(a_string, "%u", user);
844 break;
846 /* Patch from jkf@soton.ac.uk Left the %N (NIS
847 * server name) in standard_sub_basic as it is
848 * a feature for logon servers, hence uses the
849 * username. The %p (NIS server path) code is
850 * here as it is used instead of the default
851 * "path =" string in [homes] and so needs the
852 * service name, not the username. */
853 case 'p':
854 a_string = realloc_string_sub(a_string, "%p",
855 automount_path(servicename));
856 break;
858 default:
859 break;
862 p++;
863 if (a_string == NULL) {
864 return NULL;
868 ret_string = alloc_sub_basic(smb_name, domain_name, a_string);
869 SAFE_FREE(a_string);
870 return ret_string;
874 * This obviously is inefficient and needs to be merged into
875 * alloc_sub_advanced...
878 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
879 const char *servicename, const char *user,
880 const char *connectpath, gid_t gid,
881 const char *smb_name, const char *domain_name,
882 const char *str)
884 char *a, *t;
886 if (!(a = alloc_sub_advanced(servicename, user, connectpath, gid,
887 smb_name, domain_name, str))) {
888 return NULL;
890 t = talloc_strdup(mem_ctx, a);
891 SAFE_FREE(a);
892 return t;
896 void standard_sub_advanced(const char *servicename, const char *user,
897 const char *connectpath, gid_t gid,
898 const char *smb_name, const char *domain_name,
899 char *str, size_t len)
901 char *s;
903 s = alloc_sub_advanced(servicename, user, connectpath,
904 gid, smb_name, domain_name, str);
906 if ( s ) {
907 strncpy( str, s, len );
908 SAFE_FREE( s );
912 /****************************************************************************
913 Do some standard substitutions in a string.
914 ****************************************************************************/
916 char *standard_sub_conn(TALLOC_CTX *ctx, connection_struct *conn, const char *str)
918 return talloc_sub_advanced(ctx,
919 lp_servicename(SNUM(conn)),
920 conn->server_info->unix_name,
921 conn->connectpath,
922 conn->server_info->utok.gid,
923 get_smb_user_name(),
925 str);