selftest: put the target on the environment
[Samba.git] / source3 / lib / substitute.c
blobe72a8c3b6160ec0eeefca06d0925de0ef12b2419
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 "system/passwd.h"
24 #include "secrets.h"
25 #include "auth.h"
27 static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
28 const char *str);
30 userdom_struct current_user_info;
31 fstring remote_proto="UNKNOWN";
33 /**
34 * Set the 'local' machine name
35 * @param local_name the name we are being called
36 * @param if this is the 'final' name for us, not be be changed again
39 static char *local_machine;
41 void free_local_machine_name(void)
43 SAFE_FREE(local_machine);
46 bool set_local_machine_name(const char *local_name, bool perm)
48 static bool already_perm = false;
49 char *tmp_local_machine = NULL;
50 size_t len;
52 if (already_perm) {
53 return true;
56 tmp_local_machine = SMB_STRDUP(local_name);
57 if (!tmp_local_machine) {
58 return false;
60 trim_char(tmp_local_machine,' ',' ');
62 SAFE_FREE(local_machine);
63 len = strlen(tmp_local_machine);
64 local_machine = SMB_CALLOC_ARRAY(char, len+1);
65 if (!local_machine) {
66 SAFE_FREE(tmp_local_machine);
67 return false;
69 /* alpha_strcpy includes the space for the terminating nul. */
70 alpha_strcpy(local_machine,tmp_local_machine,
71 SAFE_NETBIOS_CHARS,len+1);
72 strlower_m(local_machine);
73 SAFE_FREE(tmp_local_machine);
75 already_perm = perm;
77 return true;
80 const char *get_local_machine_name(void)
82 if (!local_machine || !*local_machine) {
83 return global_myname();
86 return local_machine;
89 /**
90 * Set the 'remote' machine name
91 * @param remote_name the name our client wants to be called by
92 * @param if this is the 'final' name for them, not be be changed again
95 static char *remote_machine;
97 bool set_remote_machine_name(const char *remote_name, bool perm)
99 static bool already_perm = False;
100 char *tmp_remote_machine;
101 size_t len;
103 if (already_perm) {
104 return true;
107 tmp_remote_machine = SMB_STRDUP(remote_name);
108 if (!tmp_remote_machine) {
109 return false;
111 trim_char(tmp_remote_machine,' ',' ');
113 SAFE_FREE(remote_machine);
114 len = strlen(tmp_remote_machine);
115 remote_machine = SMB_CALLOC_ARRAY(char, len+1);
116 if (!remote_machine) {
117 SAFE_FREE(tmp_remote_machine);
118 return false;
121 /* alpha_strcpy includes the space for the terminating nul. */
122 alpha_strcpy(remote_machine,tmp_remote_machine,
123 SAFE_NETBIOS_CHARS,len+1);
124 strlower_m(remote_machine);
125 SAFE_FREE(tmp_remote_machine);
127 already_perm = perm;
129 return true;
132 const char *get_remote_machine_name(void)
134 return remote_machine ? remote_machine : "";
137 /*******************************************************************
138 Setup the string used by %U substitution.
139 ********************************************************************/
141 static char *smb_user_name;
143 void sub_set_smb_name(const char *name)
145 char *tmp;
146 size_t len;
147 bool is_machine_account = false;
149 /* don't let anonymous logins override the name */
150 if (!name || !*name) {
151 return;
154 tmp = SMB_STRDUP(name);
155 if (!tmp) {
156 return;
158 trim_char(tmp, ' ', ' ');
159 strlower_m(tmp);
161 len = strlen(tmp);
163 if (len == 0) {
164 SAFE_FREE(tmp);
165 return;
168 /* long story but here goes....we have to allow usernames
169 ending in '$' as they are valid machine account names.
170 So check for a machine account and re-add the '$'
171 at the end after the call to alpha_strcpy(). --jerry */
173 if (tmp[len-1] == '$') {
174 is_machine_account = True;
177 SAFE_FREE(smb_user_name);
178 smb_user_name = SMB_CALLOC_ARRAY(char, len+1);
179 if (!smb_user_name) {
180 SAFE_FREE(tmp);
181 return;
184 /* alpha_strcpy includes the space for the terminating nul. */
185 alpha_strcpy(smb_user_name, tmp,
186 SAFE_NETBIOS_CHARS,
187 len+1);
189 SAFE_FREE(tmp);
191 if (is_machine_account) {
192 len = strlen(smb_user_name);
193 smb_user_name[len-1] = '$';
197 static char sub_peeraddr[INET6_ADDRSTRLEN];
198 static const char *sub_peername = "";
199 static char sub_sockaddr[INET6_ADDRSTRLEN];
201 void sub_set_socket_ids(const char *peeraddr, const char *peername,
202 const char *sockaddr)
204 const char *addr = peeraddr;
206 if (strnequal(addr, "::ffff:", 7)) {
207 addr += 7;
209 strlcpy(sub_peeraddr, addr, sizeof(sub_peeraddr));
211 sub_peername = SMB_STRDUP(peername);
212 if (sub_peername == NULL) {
213 sub_peername = sub_peeraddr;
217 * Shouldn't we do the ::ffff: cancellation here as well? The
218 * original code in alloc_sub_basic() did not do it, so I'm
219 * leaving it out here as well for compatibility.
221 strlcpy(sub_sockaddr, sockaddr, sizeof(sub_sockaddr));
224 static const char *get_smb_user_name(void)
226 return smb_user_name ? smb_user_name : "";
229 /*******************************************************************
230 Setup the strings used by substitutions. Called per packet. Ensure
231 %U name is set correctly also.
233 smb_name must be sanitized by alpha_strcpy
234 ********************************************************************/
236 void set_current_user_info(const char *smb_name, const char *unix_name,
237 const char *domain)
239 fstrcpy(current_user_info.smb_name, smb_name);
240 fstrcpy(current_user_info.unix_name, unix_name);
241 fstrcpy(current_user_info.domain, domain);
243 /* The following is safe as current_user_info.smb_name
244 * has already been sanitised in register_existing_vuid. */
246 sub_set_smb_name(current_user_info.smb_name);
249 /*******************************************************************
250 Return the current active user name.
251 *******************************************************************/
253 const char *get_current_username(void)
255 if (current_user_info.smb_name[0] == '\0' ) {
256 return get_smb_user_name();
259 return current_user_info.smb_name;
262 /*******************************************************************
263 Given a pointer to a %$(NAME) in p and the whole string in str
264 expand it as an environment variable.
265 Return a new allocated and expanded string.
266 Based on code by Branko Cibej <branko.cibej@hermes.si>
267 When this is called p points at the '%' character.
268 May substitute multiple occurrencies of the same env var.
269 ********************************************************************/
271 static char * realloc_expand_env_var(char *str, char *p)
273 char *envname;
274 char *envval;
275 char *q, *r;
276 int copylen;
278 if (p[0] != '%' || p[1] != '$' || p[2] != '(') {
279 return str;
283 * Look for the terminating ')'.
286 if ((q = strchr_m(p,')')) == NULL) {
287 DEBUG(0,("expand_env_var: Unterminated environment variable [%s]\n", p));
288 return str;
292 * Extract the name from within the %$(NAME) string.
295 r = p + 3;
296 copylen = q - r;
298 /* reserve space for use later add %$() chars */
299 if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) {
300 return NULL;
303 strncpy(envname,r,copylen);
304 envname[copylen] = '\0';
306 if ((envval = getenv(envname)) == NULL) {
307 DEBUG(0,("expand_env_var: Environment variable [%s] not set\n", envname));
308 SAFE_FREE(envname);
309 return str;
313 * Copy the full %$(NAME) into envname so it
314 * can be replaced.
317 copylen = q + 1 - p;
318 strncpy(envname,p,copylen);
319 envname[copylen] = '\0';
320 r = realloc_string_sub(str, envname, envval);
321 SAFE_FREE(envname);
323 return r;
326 /*******************************************************************
327 *******************************************************************/
329 static char *longvar_domainsid( void )
331 struct dom_sid sid;
332 fstring tmp;
333 char *sid_string;
335 if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) {
336 return NULL;
339 sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) );
341 if ( !sid_string ) {
342 DEBUG(0,("longvar_domainsid: failed to dup SID string!\n"));
345 return sid_string;
348 /*******************************************************************
349 *******************************************************************/
351 struct api_longvar {
352 const char *name;
353 char* (*fn)( void );
356 static struct api_longvar longvar_table[] = {
357 { "DomainSID", longvar_domainsid },
358 { NULL, NULL }
361 static char *get_longvar_val( const char *varname )
363 int i;
365 DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname));
367 for ( i=0; longvar_table[i].name; i++ ) {
368 if ( strequal( longvar_table[i].name, varname ) ) {
369 return longvar_table[i].fn();
373 return NULL;
376 /*******************************************************************
377 Expand the long smb.conf variable names given a pointer to a %(NAME).
378 Return the number of characters by which the pointer should be advanced.
379 When this is called p points at the '%' character.
380 ********************************************************************/
382 static char *realloc_expand_longvar(char *str, char *p)
384 fstring varname;
385 char *value;
386 char *q, *r;
387 int copylen;
389 if ( p[0] != '%' || p[1] != '(' ) {
390 return str;
393 /* Look for the terminating ')'.*/
395 if ((q = strchr_m(p,')')) == NULL) {
396 DEBUG(0,("realloc_expand_longvar: Unterminated environment variable [%s]\n", p));
397 return str;
400 /* Extract the name from within the %(NAME) string.*/
402 r = p+2;
403 copylen = MIN( (q-r), (sizeof(varname)-1) );
404 strncpy(varname, r, copylen);
405 varname[copylen] = '\0';
407 if ((value = get_longvar_val(varname)) == NULL) {
408 DEBUG(0,("realloc_expand_longvar: Variable [%s] not set. Skipping\n", varname));
409 return str;
412 /* Copy the full %(NAME) into envname so it can be replaced.*/
414 copylen = MIN( (q+1-p),(sizeof(varname)-1) );
415 strncpy( varname, p, copylen );
416 varname[copylen] = '\0';
417 r = realloc_string_sub(str, varname, value);
418 SAFE_FREE( value );
420 /* skip over the %(varname) */
422 return r;
425 /*******************************************************************
426 Patch from jkf@soton.ac.uk
427 Added this to implement %p (NIS auto-map version of %H)
428 *******************************************************************/
430 static const char *automount_path(const char *user_name)
432 TALLOC_CTX *ctx = talloc_tos();
433 const char *server_path;
435 /* use the passwd entry as the default */
436 /* this will be the default if WITH_AUTOMOUNT is not used or fails */
438 server_path = talloc_strdup(ctx, get_user_home_dir(ctx, user_name));
439 if (!server_path) {
440 return "";
443 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
445 if (lp_nis_home_map()) {
446 const char *home_path_start;
447 char *automount_value = automount_lookup(ctx, user_name);
449 if(automount_value && strlen(automount_value) > 0) {
450 home_path_start = strchr_m(automount_value,':');
451 if (home_path_start != NULL) {
452 DEBUG(5, ("NIS lookup succeeded. "
453 "Home path is: %s\n",
454 home_path_start ?
455 (home_path_start+1):""));
456 server_path = talloc_strdup(ctx,
457 home_path_start+1);
458 if (!server_path) {
459 server_path = "";
462 } else {
463 /* NIS key lookup failed: default to
464 * user home directory from password file */
465 DEBUG(5, ("NIS lookup failed. Using Home path from "
466 "passwd file. Home path is: %s\n", server_path ));
469 #endif
471 DEBUG(4,("Home server path: %s\n", server_path));
472 return server_path;
475 /*******************************************************************
476 Patch from jkf@soton.ac.uk
477 This is Luke's original function with the NIS lookup code
478 moved out to a separate function.
479 *******************************************************************/
481 static const char *automount_server(const char *user_name)
483 TALLOC_CTX *ctx = talloc_tos();
484 const char *server_name;
485 const char *local_machine_name = get_local_machine_name();
487 /* use the local machine name as the default */
488 /* this will be the default if WITH_AUTOMOUNT is not used or fails */
489 if (local_machine_name && *local_machine_name) {
490 server_name = talloc_strdup(ctx, local_machine_name);
491 } else {
492 server_name = talloc_strdup(ctx, global_myname());
495 if (!server_name) {
496 return "";
499 #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
500 if (lp_nis_home_map()) {
501 char *p;
502 char *srv;
503 char *automount_value = automount_lookup(ctx, user_name);
504 if (!automount_value) {
505 return "";
507 srv = talloc_strdup(ctx, automount_value);
508 if (!srv) {
509 return "";
511 p = strchr_m(srv, ':');
512 if (!p) {
513 return "";
515 *p = '\0';
516 server_name = srv;
517 DEBUG(5, ("NIS lookup succeeded. Home server %s\n",
518 server_name));
520 #endif
522 DEBUG(4,("Home server: %s\n", server_name));
523 return server_name;
526 /****************************************************************************
527 Do some standard substitutions in a string.
528 len is the length in bytes of the space allowed in string str. If zero means
529 don't allow expansions.
530 ****************************************************************************/
532 void standard_sub_basic(const char *smb_name, const char *domain_name,
533 char *str, size_t len)
535 char *s;
537 if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) {
538 strncpy( str, s, len );
541 SAFE_FREE( s );
544 /****************************************************************************
545 Do some standard substitutions in a string.
546 This function will return an allocated string that have to be freed.
547 ****************************************************************************/
549 char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name,
550 const char *domain_name, const char *str)
552 char *a, *t;
554 if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) {
555 return NULL;
557 t = talloc_strdup(mem_ctx, a);
558 SAFE_FREE(a);
559 return t;
562 /****************************************************************************
563 ****************************************************************************/
565 static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
566 const char *str)
568 char *b, *p, *s, *r, *a_string;
569 fstring pidstr, vnnstr;
570 const char *local_machine_name = get_local_machine_name();
571 TALLOC_CTX *tmp_ctx = NULL;
573 /* workaround to prevent a crash while looking at bug #687 */
575 if (!str) {
576 DEBUG(0,("alloc_sub_basic: NULL source string! This should not happen\n"));
577 return NULL;
580 a_string = SMB_STRDUP(str);
581 if (a_string == NULL) {
582 DEBUG(0, ("alloc_sub_basic: Out of memory!\n"));
583 return NULL;
586 tmp_ctx = talloc_stackframe();
588 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
590 r = NULL;
591 b = a_string;
593 switch (*(p+1)) {
594 case 'U' :
595 r = strlower_talloc(tmp_ctx, smb_name);
596 if (r == NULL) {
597 goto error;
599 a_string = realloc_string_sub(a_string, "%U", r);
600 break;
601 case 'G' : {
602 struct passwd *pass;
603 r = talloc_strdup(tmp_ctx, smb_name);
604 if (r == NULL) {
605 goto error;
607 pass = Get_Pwnam_alloc(tmp_ctx, r);
608 if (pass != NULL) {
609 a_string = realloc_string_sub(
610 a_string, "%G",
611 gidtoname(pass->pw_gid));
613 TALLOC_FREE(pass);
614 break;
616 case 'D' :
617 r = strupper_talloc(tmp_ctx, domain_name);
618 if (r == NULL) {
619 goto error;
621 a_string = realloc_string_sub(a_string, "%D", r);
622 break;
623 case 'I' : {
624 a_string = realloc_string_sub(
625 a_string, "%I",
626 sub_peeraddr[0] ? sub_peeraddr : "0.0.0.0");
627 break;
629 case 'i':
630 a_string = realloc_string_sub(
631 a_string, "%i",
632 sub_sockaddr[0] ? sub_sockaddr : "0.0.0.0");
633 break;
634 case 'L' :
635 if ( StrnCaseCmp(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) {
636 break;
638 if (local_machine_name && *local_machine_name) {
639 a_string = realloc_string_sub(a_string, "%L", local_machine_name);
640 } else {
641 a_string = realloc_string_sub(a_string, "%L", global_myname());
643 break;
644 case 'N':
645 a_string = realloc_string_sub(a_string, "%N", automount_server(smb_name));
646 break;
647 case 'M' :
648 a_string = realloc_string_sub(a_string, "%M",
649 sub_peername);
650 break;
651 case 'R' :
652 a_string = realloc_string_sub(a_string, "%R", remote_proto);
653 break;
654 case 'T' :
655 a_string = realloc_string_sub(a_string, "%T", current_timestring(tmp_ctx, False));
656 break;
657 case 'a' :
658 a_string = realloc_string_sub(a_string, "%a",
659 get_remote_arch_str());
660 break;
661 case 'd' :
662 slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid());
663 a_string = realloc_string_sub(a_string, "%d", pidstr);
664 break;
665 case 'h' :
666 a_string = realloc_string_sub(a_string, "%h", myhostname());
667 break;
668 case 'm' :
669 a_string = realloc_string_sub(a_string, "%m",
670 remote_machine
671 ? remote_machine
672 : "");
673 break;
674 case 'v' :
675 a_string = realloc_string_sub(a_string, "%v", samba_version_string());
676 break;
677 case 'w' :
678 a_string = realloc_string_sub(a_string, "%w", lp_winbind_separator());
679 break;
680 case '$' :
681 a_string = realloc_expand_env_var(a_string, p); /* Expand environment variables */
682 break;
683 case '(':
684 a_string = realloc_expand_longvar( a_string, p );
685 break;
686 case 'V' :
687 slprintf(vnnstr,sizeof(vnnstr)-1, "%u", get_my_vnn());
688 a_string = realloc_string_sub(a_string, "%V", vnnstr);
689 break;
690 default:
691 break;
694 p++;
695 TALLOC_FREE(r);
697 if (a_string == NULL) {
698 goto done;
702 goto done;
704 error:
705 SAFE_FREE(a_string);
707 done:
708 TALLOC_FREE(tmp_ctx);
709 return a_string;
712 /****************************************************************************
713 Do some specific substitutions in a string.
714 This function will return an allocated string that have to be freed.
715 ****************************************************************************/
717 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
718 const char *input_string,
719 const char *username,
720 const char *domain,
721 uid_t uid,
722 gid_t gid)
724 char *a_string;
725 char *ret_string = NULL;
726 char *b, *p, *s;
727 TALLOC_CTX *tmp_ctx;
729 if (!(tmp_ctx = talloc_new(mem_ctx))) {
730 DEBUG(0, ("talloc_new failed\n"));
731 return NULL;
734 a_string = talloc_strdup(tmp_ctx, input_string);
735 if (a_string == NULL) {
736 DEBUG(0, ("talloc_sub_specified: Out of memory!\n"));
737 goto done;
740 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
742 b = a_string;
744 switch (*(p+1)) {
745 case 'U' :
746 a_string = talloc_string_sub(
747 tmp_ctx, a_string, "%U", username);
748 break;
749 case 'u' :
750 a_string = talloc_string_sub(
751 tmp_ctx, a_string, "%u", username);
752 break;
753 case 'G' :
754 if (gid != -1) {
755 a_string = talloc_string_sub(
756 tmp_ctx, a_string, "%G",
757 gidtoname(gid));
758 } else {
759 a_string = talloc_string_sub(
760 tmp_ctx, a_string,
761 "%G", "NO_GROUP");
763 break;
764 case 'g' :
765 if (gid != -1) {
766 a_string = talloc_string_sub(
767 tmp_ctx, a_string, "%g",
768 gidtoname(gid));
769 } else {
770 a_string = talloc_string_sub(
771 tmp_ctx, a_string, "%g", "NO_GROUP");
773 break;
774 case 'D' :
775 a_string = talloc_string_sub(tmp_ctx, a_string,
776 "%D", domain);
777 break;
778 case 'N' :
779 a_string = talloc_string_sub(
780 tmp_ctx, a_string, "%N",
781 automount_server(username));
782 break;
783 default:
784 break;
787 p++;
788 if (a_string == NULL) {
789 goto done;
793 /* Watch out, using "mem_ctx" here, so all intermediate stuff goes
794 * away with the TALLOC_FREE(tmp_ctx) further down. */
796 ret_string = talloc_sub_basic(mem_ctx, username, domain, a_string);
798 done:
799 TALLOC_FREE(tmp_ctx);
800 return ret_string;
803 /****************************************************************************
804 ****************************************************************************/
806 static char *alloc_sub_advanced(const char *servicename, const char *user,
807 const char *connectpath, gid_t gid,
808 const char *smb_name, const char *domain_name,
809 const char *str)
811 char *a_string, *ret_string;
812 char *b, *p, *s;
814 a_string = SMB_STRDUP(str);
815 if (a_string == NULL) {
816 DEBUG(0, ("alloc_sub_advanced: Out of memory!\n"));
817 return NULL;
820 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
822 b = a_string;
824 switch (*(p+1)) {
825 case 'N' :
826 a_string = realloc_string_sub(a_string, "%N", automount_server(user));
827 break;
828 case 'H': {
829 char *h;
830 if ((h = get_user_home_dir(talloc_tos(), user)))
831 a_string = realloc_string_sub(a_string, "%H", h);
832 TALLOC_FREE(h);
833 break;
835 case 'P':
836 a_string = realloc_string_sub(a_string, "%P", connectpath);
837 break;
838 case 'S':
839 a_string = realloc_string_sub(a_string, "%S", servicename);
840 break;
841 case 'g':
842 a_string = realloc_string_sub(a_string, "%g", gidtoname(gid));
843 break;
844 case 'u':
845 a_string = realloc_string_sub(a_string, "%u", user);
846 break;
848 /* Patch from jkf@soton.ac.uk Left the %N (NIS
849 * server name) in standard_sub_basic as it is
850 * a feature for logon servers, hence uses the
851 * username. The %p (NIS server path) code is
852 * here as it is used instead of the default
853 * "path =" string in [homes] and so needs the
854 * service name, not the username. */
855 case 'p':
856 a_string = realloc_string_sub(a_string, "%p",
857 automount_path(servicename));
858 break;
860 default:
861 break;
864 p++;
865 if (a_string == NULL) {
866 return NULL;
870 ret_string = alloc_sub_basic(smb_name, domain_name, a_string);
871 SAFE_FREE(a_string);
872 return ret_string;
876 * This obviously is inefficient and needs to be merged into
877 * alloc_sub_advanced...
880 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
881 const char *servicename, const char *user,
882 const char *connectpath, gid_t gid,
883 const char *smb_name, const char *domain_name,
884 const char *str)
886 char *a, *t;
888 if (!(a = alloc_sub_advanced(servicename, user, connectpath, gid,
889 smb_name, domain_name, str))) {
890 return NULL;
892 t = talloc_strdup(mem_ctx, a);
893 SAFE_FREE(a);
894 return t;
898 void standard_sub_advanced(const char *servicename, const char *user,
899 const char *connectpath, gid_t gid,
900 const char *smb_name, const char *domain_name,
901 char *str, size_t len)
903 char *s;
905 s = alloc_sub_advanced(servicename, user, connectpath,
906 gid, smb_name, domain_name, str);
908 if ( s ) {
909 strncpy( str, s, len );
910 SAFE_FREE( s );
914 /****************************************************************************
915 Do some standard substitutions in a string.
916 ****************************************************************************/
918 char *standard_sub_conn(TALLOC_CTX *ctx, connection_struct *conn, const char *str)
920 return talloc_sub_advanced(ctx,
921 lp_servicename(SNUM(conn)),
922 conn->session_info->unix_name,
923 conn->connectpath,
924 conn->session_info->utok.gid,
925 get_smb_user_name(),
927 str);