LCOV - code coverage report
Current view: top level - source3/lib - substitute.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 157 305 51.5 %
Date: 2024-06-13 04:01:37 Functions: 12 14 85.7 %

          Line data    Source code
       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             : #include "substitute.h"
      24             : #include "system/passwd.h"
      25             : #include "secrets.h"
      26             : #include "auth.h"
      27             : #include "lib/util/string_wrappers.h"
      28             : 
      29             : /* Max DNS name is 253 + '\0' */
      30             : #define MACHINE_NAME_SIZE 254
      31             : 
      32             : static char local_machine[MACHINE_NAME_SIZE];
      33             : static char remote_machine[MACHINE_NAME_SIZE];
      34             : 
      35             : userdom_struct current_user_info;
      36             : fstring remote_proto="UNKNOWN";
      37             : 
      38             : /**
      39             :  * Set the 'local' machine name
      40             :  * @param local_name the name we are being called
      41             :  * @param if this is the 'final' name for us, not be be changed again
      42             :  */
      43         376 : bool set_local_machine_name(const char *local_name, bool perm)
      44             : {
      45             :         static bool already_perm = false;
      46             :         char tmp[MACHINE_NAME_SIZE];
      47             : 
      48         376 :         if (already_perm) {
      49           0 :                 return true;
      50             :         }
      51             : 
      52         376 :         strlcpy(tmp, local_name, sizeof(tmp));
      53         376 :         trim_char(tmp, ' ', ' ');
      54             : 
      55         376 :         alpha_strcpy(local_machine,
      56             :                      tmp,
      57             :                      SAFE_NETBIOS_CHARS,
      58             :                      sizeof(local_machine) - 1);
      59         376 :         if (!strlower_m(local_machine)) {
      60           0 :                 return false;
      61             :         }
      62             : 
      63         376 :         already_perm = perm;
      64             : 
      65         376 :         return true;
      66             : }
      67             : 
      68     1425220 : const char *get_local_machine_name(void)
      69             : {
      70     1425220 :         if (local_machine[0] == '\0') {
      71     1261244 :                 return lp_netbios_name();
      72             :         }
      73             : 
      74      163976 :         return local_machine;
      75             : }
      76             : 
      77             : /**
      78             :  * Set the 'remote' machine name
      79             :  *
      80             :  * @param remote_name the name our client wants to be called by
      81             :  * @param if this is the 'final' name for them, not be be changed again
      82             :  */
      83        6730 : bool set_remote_machine_name(const char *remote_name, bool perm)
      84             : {
      85             :         static bool already_perm = False;
      86             :         char tmp[MACHINE_NAME_SIZE];
      87             : 
      88        6730 :         if (already_perm) {
      89         395 :                 return true;
      90             :         }
      91             : 
      92        6335 :         strlcpy(tmp, remote_name, sizeof(tmp));
      93        6335 :         trim_char(tmp, ' ', ' ');
      94             : 
      95        6335 :         alpha_strcpy(remote_machine,
      96             :                      tmp,
      97             :                      SAFE_NETBIOS_CHARS,
      98             :                      sizeof(remote_machine) - 1);
      99        6335 :         if (!strlower_m(remote_machine)) {
     100           0 :                 return false;
     101             :         }
     102             : 
     103        6335 :         already_perm = perm;
     104             : 
     105        6335 :         return true;
     106             : }
     107             : 
     108         376 : const char *get_remote_machine_name(void)
     109             : {
     110         376 :         return remote_machine;
     111             : }
     112             : 
     113             : static char sub_peeraddr[INET6_ADDRSTRLEN];
     114             : static const char *sub_peername = NULL;
     115             : static char sub_sockaddr[INET6_ADDRSTRLEN];
     116             : 
     117        5270 : void sub_set_socket_ids(const char *peeraddr, const char *peername,
     118             :                         const char *sockaddr)
     119             : {
     120        5270 :         const char *addr = peeraddr;
     121             : 
     122        5270 :         if (strnequal(addr, "::ffff:", 7)) {
     123           0 :                 addr += 7;
     124             :         }
     125        5270 :         strlcpy(sub_peeraddr, addr, sizeof(sub_peeraddr));
     126             : 
     127        5270 :         if (sub_peername != NULL &&
     128           0 :                         sub_peername != sub_peeraddr) {
     129           0 :                 talloc_free(discard_const_p(char,sub_peername));
     130           0 :                 sub_peername = NULL;
     131             :         }
     132        5270 :         sub_peername = talloc_strdup(NULL, peername);
     133        5270 :         if (sub_peername == NULL) {
     134           0 :                 sub_peername = sub_peeraddr;
     135             :         }
     136             : 
     137             :         /*
     138             :          * Shouldn't we do the ::ffff: cancellation here as well? The
     139             :          * original code in talloc_sub_basic() did not do it, so I'm
     140             :          * leaving it out here as well for compatibility.
     141             :          */
     142        5270 :         strlcpy(sub_sockaddr, sockaddr, sizeof(sub_sockaddr));
     143        5270 : }
     144             : 
     145             : /*******************************************************************
     146             :  Setup the strings used by substitutions. Called per packet. Ensure
     147             :  %U name is set correctly also.
     148             : 
     149             :  smb_name must be sanitized by alpha_strcpy
     150             : ********************************************************************/
     151             : 
     152       91407 : void set_current_user_info(const char *smb_name, const char *unix_name,
     153             :                            const char *domain)
     154             : {
     155             :         static const void *last_smb_name;
     156             :         static const void *last_unix_name;
     157             :         static const void *last_domain;
     158             : 
     159       91407 :         if (likely(last_smb_name == smb_name &&
     160             :             last_unix_name == unix_name &&
     161             :             last_domain == domain))
     162             :         {
     163       61642 :                 return;
     164             :         }
     165             : 
     166       29765 :         fstrcpy(current_user_info.smb_name, smb_name);
     167       29765 :         fstrcpy(current_user_info.unix_name, unix_name);
     168       29765 :         fstrcpy(current_user_info.domain, domain);
     169             : 
     170       29765 :         last_smb_name = smb_name;
     171       29765 :         last_unix_name = unix_name;
     172       29765 :         last_domain = domain;
     173             : }
     174             : 
     175             : /*******************************************************************
     176             :  Return the current active user name.
     177             : *******************************************************************/
     178             : 
     179     1404398 : const char *get_current_username(void)
     180             : {
     181     1404398 :         return current_user_info.smb_name;
     182             : }
     183             : 
     184             : /*******************************************************************
     185             :  Given a pointer to a %$(NAME) in p and the whole string in str
     186             :  expand it as an environment variable.
     187             :  str must be a talloced string.
     188             :  Return a new allocated and expanded string.
     189             :  Based on code by Branko Cibej <branko.cibej@hermes.si>
     190             :  When this is called p points at the '%' character.
     191             :  May substitute multiple occurrencies of the same env var.
     192             : ********************************************************************/
     193             : 
     194           0 : static char *realloc_expand_env_var(char *str, char *p)
     195             : {
     196             :         char *envname;
     197             :         char *envval;
     198             :         char *q, *r;
     199             :         int copylen;
     200             : 
     201           0 :         if (p[0] != '%' || p[1] != '$' || p[2] != '(') {
     202           0 :                 return str;
     203             :         }
     204             : 
     205             :         /*
     206             :          * Look for the terminating ')'.
     207             :          */
     208             : 
     209           0 :         if ((q = strchr_m(p,')')) == NULL) {
     210           0 :                 DEBUG(0,("expand_env_var: Unterminated environment variable [%s]\n", p));
     211           0 :                 return str;
     212             :         }
     213             : 
     214             :         /*
     215             :          * Extract the name from within the %$(NAME) string.
     216             :          */
     217             : 
     218           0 :         r = p + 3;
     219           0 :         copylen = q - r;
     220             : 
     221             :         /* reserve space for use later add %$() chars */
     222           0 :         if ( (envname = talloc_array(talloc_tos(), char, copylen + 1 + 4)) == NULL ) {
     223           0 :                 return NULL;
     224             :         }
     225             : 
     226           0 :         strncpy(envname,r,copylen);
     227           0 :         envname[copylen] = '\0';
     228             : 
     229           0 :         if ((envval = getenv(envname)) == NULL) {
     230           0 :                 DEBUG(0,("expand_env_var: Environment variable [%s] not set\n", envname));
     231           0 :                 TALLOC_FREE(envname);
     232           0 :                 return str;
     233             :         }
     234             : 
     235             :         /*
     236             :          * Copy the full %$(NAME) into envname so it
     237             :          * can be replaced.
     238             :          */
     239             : 
     240           0 :         copylen = q + 1 - p;
     241           0 :         strncpy(envname,p,copylen);
     242           0 :         envname[copylen] = '\0';
     243           0 :         r = realloc_string_sub(str, envname, envval);
     244           0 :         TALLOC_FREE(envname);
     245             : 
     246           0 :         return r;
     247             : }
     248             : 
     249             : /****************************************************************************
     250             :  Do some standard substitutions in a string.
     251             :  len is the length in bytes of the space allowed in string str. If zero means
     252             :  don't allow expansions.
     253             : ****************************************************************************/
     254             : 
     255     1061305 : void standard_sub_basic(const char *smb_name, const char *domain_name,
     256             :                         char *str, size_t len)
     257             : {
     258             :         char *s;
     259             : 
     260     1061305 :         if ( (s = talloc_sub_basic(talloc_tos(), smb_name, domain_name, str )) != NULL ) {
     261     1061305 :                 strncpy( str, s, len );
     262             :         }
     263             : 
     264     1061305 :         TALLOC_FREE( s );
     265     1061305 : }
     266             : 
     267             : /*
     268             :  * Limit addresses to hexalpha charactes and underscore, safe for path
     269             :  * components for Windows clients.
     270             :  */
     271           0 : static void make_address_pathsafe(char *addr)
     272             : {
     273           0 :         while(addr && *addr) {
     274           0 :                 if(!isxdigit(*addr)) {
     275           0 :                         *addr = '_';
     276             :                 }
     277           0 :                 ++addr;
     278             :         }
     279           0 : }
     280             : 
     281             : /****************************************************************************
     282             :  Do some standard substitutions in a string.
     283             :  This function will return a talloced string that has to be freed.
     284             : ****************************************************************************/
     285             : 
     286     1425212 : char *talloc_sub_basic(TALLOC_CTX *mem_ctx,
     287             :                         const char *smb_name,
     288             :                         const char *domain_name,
     289             :                         const char *str)
     290             : {
     291             :         char *b, *p, *s, *r, *a_string;
     292             :         fstring pidstr, vnnstr;
     293     1425212 :         const char *local_machine_name = get_local_machine_name();
     294     1425212 :         TALLOC_CTX *tmp_ctx = NULL;
     295             : 
     296             :         /* workaround to prevent a crash while looking at bug #687 */
     297             : 
     298     1425212 :         if (!str) {
     299           0 :                 DEBUG(0,("talloc_sub_basic: NULL source string!  This should not happen\n"));
     300           0 :                 return NULL;
     301             :         }
     302             : 
     303     1425212 :         a_string = talloc_strdup(mem_ctx, str);
     304     1425212 :         if (a_string == NULL) {
     305           0 :                 DEBUG(0, ("talloc_sub_basic: Out of memory!\n"));
     306           0 :                 return NULL;
     307             :         }
     308             : 
     309     1425212 :         tmp_ctx = talloc_stackframe();
     310             : 
     311     1469138 :         for (s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
     312             : 
     313       43926 :                 r = NULL;
     314       43926 :                 b = a_string;
     315             : 
     316       43926 :                 switch (*(p+1)) {
     317       17430 :                 case 'U' : 
     318       17430 :                         r = strlower_talloc(tmp_ctx, smb_name);
     319       17430 :                         if (r == NULL) {
     320           0 :                                 goto error;
     321             :                         }
     322       17430 :                         a_string = realloc_string_sub(a_string, "%U", r);
     323       17430 :                         break;
     324          60 :                 case 'G' : {
     325             :                         struct passwd *pass;
     326          60 :                         bool is_domain_name = false;
     327          60 :                         const char *sep = lp_winbind_separator();
     328             : 
     329         120 :                         if (domain_name != NULL && domain_name[0] != '\0' &&
     330          60 :                             (lp_security() == SEC_ADS ||
     331           0 :                              lp_security() == SEC_DOMAIN)) {
     332          60 :                                 r = talloc_asprintf(tmp_ctx,
     333             :                                                     "%s%c%s",
     334             :                                                     domain_name,
     335          60 :                                                     *sep,
     336             :                                                     smb_name);
     337          60 :                                 is_domain_name = true;
     338             :                         } else {
     339           0 :                                 r = talloc_strdup(tmp_ctx, smb_name);
     340             :                         }
     341          60 :                         if (r == NULL) {
     342           0 :                                 goto error;
     343             :                         }
     344             : 
     345          60 :                         pass = Get_Pwnam_alloc(tmp_ctx, r);
     346          60 :                         if (pass != NULL) {
     347             :                                 char *group_name;
     348             : 
     349          36 :                                 group_name = gidtoname(pass->pw_gid);
     350          36 :                                 if (is_domain_name) {
     351             :                                         char *group_sep;
     352          36 :                                         group_sep = strchr_m(group_name, *sep);
     353          36 :                                         if (group_sep != NULL) {
     354          36 :                                                 group_name = group_sep + 1;
     355             :                                         }
     356             :                                 }
     357          36 :                                 a_string = realloc_string_sub(a_string,
     358             :                                                               "%G",
     359             :                                                               group_name);
     360             :                         }
     361          60 :                         TALLOC_FREE(pass);
     362          60 :                         break;
     363             :                 }
     364         108 :                 case 'D' :
     365         108 :                         r = strupper_talloc(tmp_ctx, domain_name);
     366         108 :                         if (r == NULL) {
     367           0 :                                 goto error;
     368             :                         }
     369         108 :                         a_string = realloc_string_sub(a_string, "%D", r);
     370         108 :                         break;
     371           0 :                 case 'I' : {
     372           0 :                         a_string = realloc_string_sub(
     373             :                                 a_string, "%I",
     374           0 :                                 sub_peeraddr[0] ? sub_peeraddr : "0.0.0.0");
     375           0 :                         break;
     376             :                 }
     377           0 :                 case 'J' : {
     378           0 :                         r = talloc_strdup(tmp_ctx,
     379           0 :                                 sub_peeraddr[0] ? sub_peeraddr : "0.0.0.0");
     380           0 :                         make_address_pathsafe(r);
     381           0 :                         a_string = realloc_string_sub(a_string, "%J", r);
     382           0 :                         break;
     383             :                 }
     384           0 :                 case 'i': 
     385           0 :                         a_string = realloc_string_sub(
     386             :                                 a_string, "%i",
     387           0 :                                 sub_sockaddr[0] ? sub_sockaddr : "0.0.0.0");
     388           0 :                         break;
     389           0 :                 case 'j' : {
     390           0 :                         r = talloc_strdup(tmp_ctx,
     391           0 :                                 sub_sockaddr[0] ? sub_sockaddr : "0.0.0.0");
     392           0 :                         make_address_pathsafe(r);
     393           0 :                         a_string = realloc_string_sub(a_string, "%j", r);
     394           0 :                         break;
     395             :                 }
     396           0 :                 case 'L' : 
     397           0 :                         if ( strncasecmp_m(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) {
     398           0 :                                 break;
     399             :                         }
     400           0 :                         if (local_machine_name && *local_machine_name) {
     401           0 :                                 a_string = realloc_string_sub(a_string, "%L", local_machine_name); 
     402             :                         } else {
     403           0 :                                 a_string = realloc_string_sub(a_string, "%L", lp_netbios_name());
     404             :                         }
     405           0 :                         break;
     406        6550 :                 case 'N' :
     407        6550 :                         a_string = realloc_string_sub(a_string,
     408             :                                                       "%N",
     409             :                                                       lp_netbios_name());
     410        6550 :                         break;
     411           0 :                 case 'M' :
     412           0 :                         a_string = realloc_string_sub(a_string, "%M",
     413           0 :                                                       sub_peername ? sub_peername : "");
     414           0 :                         break;
     415           0 :                 case 'R' :
     416           0 :                         a_string = realloc_string_sub(a_string, "%R", remote_proto);
     417           0 :                         break;
     418           0 :                 case 'T' :
     419           0 :                         a_string = realloc_string_sub(a_string, "%T", current_timestring(tmp_ctx, False));
     420           0 :                         break;
     421          58 :                 case 't' :
     422          58 :                         a_string = realloc_string_sub(a_string, "%t",
     423          58 :                                                       current_minimal_timestring(tmp_ctx, False));
     424          58 :                         break;
     425           0 :                 case 'a' :
     426           0 :                         a_string = realloc_string_sub(a_string, "%a",
     427             :                                         get_remote_arch_str());
     428           0 :                         break;
     429           0 :                 case 'd' :
     430           0 :                         slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)getpid());
     431           0 :                         a_string = realloc_string_sub(a_string, "%d", pidstr);
     432           0 :                         break;
     433           0 :                 case 'h' :
     434           0 :                         a_string = realloc_string_sub(a_string, "%h", myhostname());
     435           0 :                         break;
     436       19609 :                 case 'm' :
     437       19609 :                         a_string = realloc_string_sub(a_string, "%m",
     438             :                                                       remote_machine);
     439       19609 :                         break;
     440           0 :                 case 'v' :
     441           0 :                         a_string = realloc_string_sub(a_string, "%v", samba_version_string());
     442           0 :                         break;
     443           0 :                 case 'w' :
     444           0 :                         a_string = realloc_string_sub(a_string, "%w", lp_winbind_separator());
     445           0 :                         break;
     446           0 :                 case '$' :
     447           0 :                         a_string = realloc_expand_env_var(a_string, p); /* Expand environment variables */
     448           0 :                         break;
     449           0 :                 case 'V' :
     450           0 :                         slprintf(vnnstr,sizeof(vnnstr)-1, "%u", get_my_vnn());
     451           0 :                         a_string = realloc_string_sub(a_string, "%V", vnnstr);
     452           0 :                         break;
     453         111 :                 default: 
     454         111 :                         break;
     455             :                 }
     456             : 
     457       43926 :                 p++;
     458       43926 :                 TALLOC_FREE(r);
     459             : 
     460       43926 :                 if (a_string == NULL) {
     461           0 :                         goto done;
     462             :                 }
     463             :         }
     464             : 
     465     1425212 :         goto done;
     466             : 
     467           0 : error:
     468           0 :         TALLOC_FREE(a_string);
     469             : 
     470      840378 : done:
     471     1425212 :         TALLOC_FREE(tmp_ctx);
     472     1425212 :         return a_string;
     473             : }
     474             : 
     475             : /****************************************************************************
     476             :  Do some specific substitutions in a string.
     477             :  This function will return an allocated string that have to be freed.
     478             : ****************************************************************************/
     479             : 
     480       12888 : char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
     481             :                         const char *input_string,
     482             :                         const char *username,
     483             :                         const char *grpname,
     484             :                         const char *domain,
     485             :                         uid_t uid,
     486             :                         gid_t gid)
     487             : {
     488             :         char *a_string;
     489       12888 :         char *ret_string = NULL;
     490             :         char *b, *p, *s;
     491             :         TALLOC_CTX *tmp_ctx;
     492             : 
     493       12888 :         if (!(tmp_ctx = talloc_new(mem_ctx))) {
     494           0 :                 DEBUG(0, ("talloc_new failed\n"));
     495           0 :                 return NULL;
     496             :         }
     497             : 
     498       12888 :         a_string = talloc_strdup(tmp_ctx, input_string);
     499       12888 :         if (a_string == NULL) {
     500           0 :                 DEBUG(0, ("talloc_sub_specified: Out of memory!\n"));
     501           0 :                 goto done;
     502             :         }
     503             : 
     504       27262 :         for (s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
     505             : 
     506       14374 :                 b = a_string;
     507             : 
     508       14374 :                 switch (*(p+1)) {
     509        6442 :                 case 'U' : 
     510        6442 :                         a_string = talloc_string_sub(
     511             :                                 tmp_ctx, a_string, "%U", username);
     512        6442 :                         break;
     513           0 :                 case 'u' : 
     514           0 :                         a_string = talloc_string_sub(
     515             :                                 tmp_ctx, a_string, "%u", username);
     516           0 :                         break;
     517        1490 :                 case 'G' :
     518        1490 :                         if (gid != -1) {
     519             :                                 const char *name;
     520             : 
     521        1490 :                                 if (grpname != NULL) {
     522        1490 :                                         name = grpname;
     523             :                                 } else {
     524           0 :                                         name = gidtoname(gid);
     525             :                                 }
     526             : 
     527        1490 :                                 a_string = talloc_string_sub(tmp_ctx,
     528             :                                                              a_string,
     529             :                                                              "%G",
     530             :                                                              name);
     531             :                         } else {
     532           0 :                                 a_string = talloc_string_sub(
     533             :                                         tmp_ctx, a_string,
     534             :                                         "%G", "NO_GROUP");
     535             :                         }
     536        1490 :                         break;
     537           0 :                 case 'g' :
     538           0 :                         if (gid != -1) {
     539             :                                 const char *name;
     540             : 
     541           0 :                                 if (grpname != NULL) {
     542           0 :                                         name = grpname;
     543             :                                 } else {
     544           0 :                                         name = gidtoname(gid);
     545             :                                 }
     546             : 
     547           0 :                                 a_string = talloc_string_sub(tmp_ctx,
     548             :                                                              a_string,
     549             :                                                              "%g",
     550             :                                                              name);
     551             :                         } else {
     552           0 :                                 a_string = talloc_string_sub(
     553             :                                         tmp_ctx, a_string, "%g", "NO_GROUP");
     554             :                         }
     555           0 :                         break;
     556        4606 :                 case 'D' :
     557        4606 :                         a_string = talloc_string_sub(tmp_ctx, a_string,
     558             :                                                      "%D", domain);
     559        4606 :                         break;
     560        1836 :                 case 'N' :
     561        1836 :                         a_string = talloc_string_sub(tmp_ctx, a_string,
     562             :                                                      "%N", lp_netbios_name());
     563        1836 :                         break;
     564           0 :                 default: 
     565           0 :                         break;
     566             :                 }
     567             : 
     568       14374 :                 p++;
     569       14374 :                 if (a_string == NULL) {
     570           0 :                         goto done;
     571             :                 }
     572             :         }
     573             : 
     574             :         /* Watch out, using "mem_ctx" here, so all intermediate stuff goes
     575             :          * away with the TALLOC_FREE(tmp_ctx) further down. */
     576             : 
     577       12888 :         ret_string = talloc_sub_basic(mem_ctx, username, domain, a_string);
     578             : 
     579       12888 :  done:
     580       12888 :         TALLOC_FREE(tmp_ctx);
     581       12888 :         return ret_string;
     582             : }
     583             : 
     584             : /****************************************************************************
     585             : ****************************************************************************/
     586             : 
     587       10650 : char *talloc_sub_advanced(TALLOC_CTX *ctx,
     588             :                         const char *servicename,
     589             :                         const char *user,
     590             :                         const char *connectpath,
     591             :                         gid_t gid,
     592             :                         const char *str)
     593             : {
     594             :         char *a_string;
     595             :         char *b, *p, *s;
     596             : 
     597       10650 :         a_string = talloc_strdup(talloc_tos(), str);
     598       10650 :         if (a_string == NULL) {
     599           0 :                 DEBUG(0, ("talloc_sub_advanced_only: Out of memory!\n"));
     600           0 :                 return NULL;
     601             :         }
     602             : 
     603       10654 :         for (s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
     604             : 
     605           4 :                 b = a_string;
     606             : 
     607           4 :                 switch (*(p+1)) {
     608           0 :                 case 'N':
     609           0 :                         a_string = realloc_string_sub(a_string,
     610             :                                                       "%N",
     611             :                                                       lp_netbios_name());
     612           0 :                         break;
     613           0 :                 case 'H': {
     614             :                         char *h;
     615           0 :                         if ((h = get_user_home_dir(talloc_tos(), user)))
     616           0 :                                 a_string = realloc_string_sub(a_string, "%H", h);
     617           0 :                         TALLOC_FREE(h);
     618           0 :                         break;
     619             :                 }
     620           0 :                 case 'P': 
     621           0 :                         a_string = realloc_string_sub(a_string, "%P", connectpath); 
     622           0 :                         break;
     623           0 :                 case 'S': 
     624           0 :                         a_string = realloc_string_sub(a_string, "%S", servicename);
     625           0 :                         break;
     626           2 :                 case 'g': 
     627           2 :                         a_string = realloc_string_sub(a_string, "%g", gidtoname(gid)); 
     628           2 :                         break;
     629           2 :                 case 'u': 
     630           2 :                         a_string = realloc_string_sub(a_string, "%u", user); 
     631           2 :                         break;
     632           0 :                 default: 
     633           0 :                         break;
     634             :                 }
     635             : 
     636           4 :                 p++;
     637           4 :                 if (a_string == NULL) {
     638           0 :                         return NULL;
     639             :                 }
     640             :         }
     641             : 
     642       10650 :         return a_string;
     643             : }
     644             : 
     645       10650 : char *talloc_sub_full(TALLOC_CTX *ctx,
     646             :                         const char *servicename,
     647             :                         const char *user,
     648             :                         const char *connectpath,
     649             :                         gid_t gid,
     650             :                         const char *smb_name,
     651             :                         const char *domain_name,
     652             :                         const char *str)
     653             : {
     654             :         char *a_string, *ret_string;
     655             : 
     656       10650 :         a_string = talloc_sub_advanced(ctx, servicename, user, connectpath,
     657             :                                        gid, str);
     658       10650 :         if (a_string == NULL) {
     659           0 :                 return NULL;
     660             :         }
     661             : 
     662       10650 :         ret_string = talloc_sub_basic(ctx, smb_name, domain_name, a_string);
     663       10650 :         TALLOC_FREE(a_string);
     664       10650 :         return ret_string;
     665             : }

Generated by: LCOV version 1.13