summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-02-20 19:48:01 +0000
committerJeremy Allison <jra@samba.org>1998-02-20 19:48:01 +0000
commitc16d4aec00230983973be3b827d1209f5db65d9c (patch)
tree40c9ce5caeef8211ef2381dee11ac8d1200ecc08 /source3/lib/util.c
parentc57e8d404d8ab32fe08e9f85d5326160671b56d5 (diff)
downloadsamba-c16d4aec00230983973be3b827d1209f5db65d9c.tar.gz
samba-c16d4aec00230983973be3b827d1209f5db65d9c.tar.bz2
samba-c16d4aec00230983973be3b827d1209f5db65d9c.zip
nmbd_packets.c: nmbd_subnetdb.c: Patch from Andrey Alekseyev <fetch@muffin.arcadia.spb.ru>
to fix the fact that retransmit_or_expire_response_records() wasn't looking at the WINS subnet. server.c: Patch from jkf@soton.ac.uk to add %p (NIS server path) substitution. smbpass.c: Fix to stop parsing failing on non-valid lines. trans2.c: Fix for volume serial number code. util.c: Patch from jkf@soton.ac.uk to add %p (NIS server path) substitution. Fix for warnings under RH5. gcc 2.8. Jeremy. (This used to be commit e58ab3bbe6e939ba678ad5482e58e0191c8dcbcb)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r--source3/lib/util.c142
1 files changed, 112 insertions, 30 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index fa5f6ae400..365a765174 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1580,12 +1580,12 @@ BOOL reduce_name(char *s,char *dir,BOOL widelinks)
#else
pstring dir2;
pstring wd;
- pstring basename;
+ pstring base_name;
pstring newname;
char *p=NULL;
BOOL relative = (*s != '/');
- *dir2 = *wd = *basename = *newname = 0;
+ *dir2 = *wd = *base_name = *newname = 0;
if (widelinks)
{
@@ -1608,8 +1608,8 @@ BOOL reduce_name(char *s,char *dir,BOOL widelinks)
/* remove any double slashes */
string_sub(s,"//","/");
- pstrcpy(basename,s);
- p = strrchr(basename,'/');
+ pstrcpy(base_name,s);
+ p = strrchr(base_name,'/');
if (!p)
return(True);
@@ -1634,7 +1634,7 @@ BOOL reduce_name(char *s,char *dir,BOOL widelinks)
}
- if (p && (p != basename))
+ if (p && (p != base_name))
{
*p = 0;
if (strcmp(p+1,".")==0)
@@ -1643,10 +1643,10 @@ BOOL reduce_name(char *s,char *dir,BOOL widelinks)
*p = '/';
}
- if (ChDir(basename) != 0)
+ if (ChDir(base_name) != 0)
{
ChDir(wd);
- DEBUG(3,("couldn't chdir for %s %s basename=%s\n",s,dir,basename));
+ DEBUG(3,("couldn't chdir for %s %s basename=%s\n",s,dir,base_name));
return(False);
}
@@ -1657,7 +1657,7 @@ BOOL reduce_name(char *s,char *dir,BOOL widelinks)
return(False);
}
- if (p && (p != basename))
+ if (p && (p != base_name))
{
strcat(newname,"/");
strcat(newname,p+1);
@@ -3713,44 +3713,88 @@ char *client_addr(void)
return addr_buf;
}
+/*******************************************************************
+ Patch from jkf@soton.ac.uk
+ Split Luke's automount_server into YP lookup and string splitter
+ so can easily implement automount_path().
+ As we may end up doing both, cache the last YP result.
+*******************************************************************/
+
+#if (defined(NETGROUP) && defined(AUTOMOUNT))
+static char *automount_lookup(char *user_name)
+{
+ static fstring last_key = "";
+ static pstring last_value = "";
+
+ int nis_error; /* returned by yp all functions */
+ char *nis_result; /* yp_match inits this */
+ int nis_result_len; /* and set this */
+ char *nis_domain; /* yp_get_default_domain inits this */
+ char *nis_map = (char *)lp_nis_home_map_name();
+
+ if ((nis_error = yp_get_default_domain(&nis_domain)) != 0)
+ {
+ DEBUG(3, ("YP Error: %s\n", yperr_string(nis_error)));
+ return last_value;
+ }
+
+ DEBUG(5, ("NIS Domain: %s\n", nis_domain));
+
+ if (!strcmp(user_name, last_key))
+ {
+ nis_result = last_value;
+ nis_result_len = strlen(last_value);
+ nis_error = 0;
+ }
+ else
+ {
+ if ((nis_error = yp_match(nis_domain, nis_map,
+ user_name, strlen(user_name),
+ &nis_result, &nis_result_len)) != 0)
+ {
+ DEBUG(3, ("YP Error: \"%s\" while looking up \"%s\" in map \"%s\"\n",
+ yperr_string(nis_error), user_name, nis_map));
+ }
+ if (!nis_error && nis_result_len >= sizeof(pstring))
+ {
+ nis_result_len = sizeof(pstring)-1;
+ }
+ fstrcpy(last_key, user_name);
+ strncpy(last_value, nis_result, nis_result_len);
+ last_value[nis_result_len] = '\0';
+ }
+
+ DEBUG(4, ("YP Lookup: %s resulted in %s\n", user_name, last_value));
+ return last_value;
+}
+#endif
+
+/*******************************************************************
+ Patch from jkf@soton.ac.uk
+ This is Luke's original function with the NIS lookup code
+ moved out to a separate function.
+*******************************************************************/
+
char *automount_server(char *user_name)
{
static pstring server_name;
#if (defined(NETGROUP) && defined (AUTOMOUNT))
- int nis_error; /* returned by yp all functions */
- char *nis_result; /* yp_match inits this */
- int nis_result_len; /* and set this */
- char *nis_domain; /* yp_get_default_domain inits this */
- char *nis_map = (char *)lp_nis_home_map_name();
int home_server_len;
/* set to default of local machine */
pstrcpy(server_name, local_machine);
- if ((nis_error = yp_get_default_domain(&nis_domain)) != 0)
+ if (lp_nis_home_map())
{
- DEBUG(3, ("YP Error: %s\n", yperr_string(nis_error)));
- }
-
- DEBUG(5, ("NIS Domain: %s\n", nis_domain));
-
- if ((nis_error = yp_match(nis_domain, nis_map,
- user_name, strlen(user_name),
- &nis_result, &nis_result_len)) != 0)
- {
- DEBUG(3, ("YP Error: %s\n", yperr_string(nis_error)));
- }
-
- if (!nis_error && lp_nis_home_map())
- {
- home_server_len = strcspn(nis_result,":");
+ char *automount_value = automount_lookup(user_name);
+ home_server_len = strcspn(automount_value,":");
DEBUG(5, ("NIS lookup succeeded. Home server length: %d\n",home_server_len));
if (home_server_len > sizeof(pstring))
{
home_server_len = sizeof(pstring);
}
- strncpy(server_name, nis_result, home_server_len);
+ strncpy(server_name, automount_value, home_server_len);
server_name[home_server_len] = '\0';
}
#else
@@ -3764,6 +3808,44 @@ char *automount_server(char *user_name)
}
/*******************************************************************
+ Patch from jkf@soton.ac.uk
+ Added this to implement %p (NIS auto-map version of %H)
+*******************************************************************/
+
+char *automount_path(char *user_name)
+{
+ static pstring server_path;
+
+#if (defined(NETGROUP) && defined (AUTOMOUNT))
+ char *home_path_start;
+
+ /* set to default of no string */
+ server_path[0] = 0;
+
+ if (lp_nis_home_map())
+ {
+ char *automount_value = automount_lookup(user_name);
+ home_path_start = strchr(automount_value,':');
+ if (home_path_start != NULL)
+ {
+ DEBUG(5, ("NIS lookup succeeded. Home path is: %s\n",
+ home_path_start?(home_path_start+1):""));
+ strcpy(server_path, home_path_start+1);
+ }
+ }
+#else
+ /* use the passwd entry instead of the auto-map server entry */
+ /* pstrcpy() copes with get_home_dir() returning NULL */
+ pstrcpy(server_path, get_home_dir(user_name));
+#endif
+
+ DEBUG(4,("Home server path: %s\n", server_path));
+
+ return server_path;
+}
+
+
+/*******************************************************************
sub strings with useful parameters
Rewritten by Stefaan A Eeckels <Stefaan.Eeckels@ecc.lu> and
Paul Rippin <pr3245@nopc.eurostat.cec.be>