string substitution functions
Copyright (C) Andrew Tridgell 1992-2000
Copyright (C) Gerald Carter 2006
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
+#include "secrets.h"
-extern struct current_user current_user;
+static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
+ const char *str);
userdom_struct current_user_info;
fstring remote_proto="UNKNOWN";
********************************************************************/
void set_current_user_info(const char *smb_name, const char *unix_name,
- const char *full_name, const char *domain)
+ const char *domain)
{
fstrcpy(current_user_info.smb_name, smb_name);
fstrcpy(current_user_info.unix_name, unix_name);
- fstrcpy(current_user_info.full_name, full_name);
fstrcpy(current_user_info.domain, domain);
/* The following is safe as current_user_info.smb_name
r = p + 3;
copylen = q - r;
-
+
/* reserve space for use later add %$() chars */
if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) {
return NULL;
}
-
+
strncpy(envname,r,copylen);
envname[copylen] = '\0';
envname[copylen] = '\0';
r = realloc_string_sub(str, envname, envval);
SAFE_FREE(envname);
-
+
return r;
}
static char *longvar_domainsid( void )
{
- DOM_SID sid;
+ struct dom_sid sid;
fstring tmp;
char *sid_string;
-
+
if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) {
return NULL;
}
-
+
sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) );
-
+
if ( !sid_string ) {
DEBUG(0,("longvar_domainsid: failed to dup SID string!\n"));
}
-
+
return sid_string;
}
static char *get_longvar_val( const char *varname )
{
int i;
-
+
DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname));
-
+
for ( i=0; longvar_table[i].name; i++ ) {
if ( strequal( longvar_table[i].name, varname ) ) {
return longvar_table[i].fn();
}
}
-
+
return NULL;
}
char *str, size_t len)
{
char *s;
-
+
if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) {
strncpy( str, s, len );
}
-
+
SAFE_FREE( s );
-
}
/****************************************************************************
const char *domain_name, const char *str)
{
char *a, *t;
-
+
if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) {
return NULL;
}
/****************************************************************************
****************************************************************************/
-char *alloc_sub_basic(const char *smb_name, const char *domain_name,
- const char *str)
+static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
+ const char *str)
{
char *b, *p, *s, *r, *a_string;
fstring pidstr, vnnstr;
TALLOC_CTX *tmp_ctx = NULL;
/* workaround to prevent a crash while looking at bug #687 */
-
+
if (!str) {
DEBUG(0,("alloc_sub_basic: NULL source string! This should not happen\n"));
return NULL;
}
-
+
a_string = SMB_STRDUP(str);
if (a_string == NULL) {
DEBUG(0, ("alloc_sub_basic: Out of memory!\n"));
switch (*(p+1)) {
case 'U' :
- r = strdup_lower(smb_name);
+ r = strlower_talloc(tmp_ctx, smb_name);
if (r == NULL) {
goto error;
}
break;
case 'G' : {
struct passwd *pass;
- r = SMB_STRDUP(smb_name);
+ r = talloc_strdup(tmp_ctx, smb_name);
if (r == NULL) {
goto error;
}
break;
}
case 'D' :
- r = strdup_upper(domain_name);
+ r = strupper_talloc(tmp_ctx, domain_name);
if (r == NULL) {
goto error;
}
a_string = realloc_string_sub(a_string, "%h", myhostname());
break;
case 'm' :
- a_string = realloc_string_sub(a_string, "%m", remote_machine);
+ a_string = realloc_string_sub(a_string, "%m",
+ remote_machine
+ ? remote_machine
+ : "");
break;
case 'v' :
- a_string = realloc_string_sub(a_string, "%v", SAMBA_VERSION_STRING);
+ a_string = realloc_string_sub(a_string, "%v", samba_version_string());
break;
case 'w' :
a_string = realloc_string_sub(a_string, "%w", lp_winbind_separator());
}
p++;
- SAFE_FREE(r);
+ TALLOC_FREE(r);
if (a_string == NULL) {
goto done;
DEBUG(0, ("talloc_sub_specified: Out of memory!\n"));
goto done;
}
-
+
for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
-
+
b = a_string;
-
+
switch (*(p+1)) {
case 'U' :
a_string = talloc_string_sub(
DEBUG(0, ("alloc_sub_advanced: Out of memory!\n"));
return NULL;
}
-
+
for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
-
+
b = a_string;
-
+
switch (*(p+1)) {
case 'N' :
a_string = realloc_string_sub(a_string, "%N", automount_server(user));
case 'u':
a_string = realloc_string_sub(a_string, "%u", user);
break;
-
+
/* Patch from jkf@soton.ac.uk Left the %N (NIS
* server name) in standard_sub_basic as it is
* a feature for logon servers, hence uses the
a_string = realloc_string_sub(a_string, "%p",
automount_path(servicename));
break;
-
+
default:
break;
}
lp_servicename(SNUM(conn)),
conn->server_info->unix_name,
conn->connectpath,
- conn->server_info->gid,
+ conn->server_info->utok.gid,
get_smb_user_name(),
"",
str);