summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-04-16 11:17:19 +0000
committerAndrew Tridgell <tridge@samba.org>2000-04-16 11:17:19 +0000
commit384ecd9d66ccd31ee85000c0ca55d413d8f2cc53 (patch)
tree959d2df089a89bfe6b64b737063900fc9fc1c7bb
parenta09470817c5b21dba42f9ef4ce5e8b768a254c0b (diff)
downloadsamba-384ecd9d66ccd31ee85000c0ca55d413d8f2cc53.tar.gz
samba-384ecd9d66ccd31ee85000c0ca55d413d8f2cc53.tar.xz
samba-384ecd9d66ccd31ee85000c0ca55d413d8f2cc53.zip
converted a couple more functions to use a fd instead of a FILE*
added a new utility fn file_lines_slashcont() which is used to handle files that treat a \ followed by a newline as a blank
-rw-r--r--source/include/proto.h1
-rw-r--r--source/lib/util_file.c23
-rw-r--r--source/smbd/groupname.c15
-rw-r--r--source/smbd/password.c17
4 files changed, 41 insertions, 15 deletions
diff --git a/source/include/proto.h b/source/include/proto.h
index dc9d9c389ec..27711f2ed4c 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -383,6 +383,7 @@ char *file_load(char *fname, size_t *size);
char **file_lines_load(char *fname, int *numlines);
char **file_lines_pload(char *syscmd, int *numlines);
void file_lines_free(char **lines);
+void file_lines_slashcont(char **lines);
/*The following definitions come from lib/util_sec.c */
diff --git a/source/lib/util_file.c b/source/lib/util_file.c
index 1ef713b105a..f3e28795874 100644
--- a/source/lib/util_file.c
+++ b/source/lib/util_file.c
@@ -473,3 +473,26 @@ void file_lines_free(char **lines)
free(lines);
}
+
+/****************************************************************************
+take a lislist of lines and modify them to produce a list where \ continues
+a line
+****************************************************************************/
+void file_lines_slashcont(char **lines)
+{
+ int i, j;
+
+ for (i=0; lines[i];) {
+ int len = strlen(lines[i]);
+ if (lines[i][len-1] == '\\') {
+ lines[i][len-1] = ' ';
+ if (lines[i+1]) {
+ char *p = &lines[i][len];
+ while (p < lines[i+1]) *p++ = ' ';
+ for (j = i+1; lines[j]; j++) lines[j] = lines[j+1];
+ }
+ } else {
+ i++;
+ }
+ }
+}
diff --git a/source/smbd/groupname.c b/source/smbd/groupname.c
index 4dadfaa9396..fcbf5dd7788 100644
--- a/source/smbd/groupname.c
+++ b/source/smbd/groupname.c
@@ -71,9 +71,8 @@ void load_groupname_map(void)
static BOOL initialized = False;
char *groupname_map_file = lp_groupname_map();
SMB_STRUCT_STAT st;
- FILE *fp;
- char *s;
- pstring buf;
+ char **lines;
+ int i;
groupname_map_entry *new_ep;
if(!initialized) {
@@ -102,12 +101,13 @@ void load_groupname_map(void)
* Load the file.
*/
- fp = sys_fopen(groupname_map_file,"r");
- if (!fp) {
+ lines = file_lines_load(groupname_map_file,NULL);
+ if (!lines) {
DEBUG(0,("load_groupname_map: can't open groupname map %s. Error was %s\n",
groupname_map_file, strerror(errno)));
return;
}
+ file_lines_slashcont(lines);
/*
* Throw away any previous list.
@@ -116,11 +116,12 @@ void load_groupname_map(void)
DEBUG(4,("load_groupname_map: Scanning groupname map %s\n",groupname_map_file));
- while((s=fgets_slash(buf,sizeof(buf),fp))!=NULL) {
+ for (i=0; lines[i]; i++) {
pstring unixname;
pstring windows_name;
struct group *gptr;
DOM_SID tmp_sid;
+ char *s = lines[i];
DEBUG(10,("load_groupname_map: Read line |%s|\n", s));
@@ -202,7 +203,7 @@ Error was %s.\n", unixname, strerror(errno) ));
DEBUG(10,("load_groupname_map: Added %ld entries to groupname map.\n",
ubi_slCount(&groupname_map_list)));
- fclose(fp);
+ file_lines_free(lines);
}
/***********************************************************
diff --git a/source/smbd/password.c b/source/smbd/password.c
index 208dbd2bffa..f92d31718c2 100644
--- a/source/smbd/password.c
+++ b/source/smbd/password.c
@@ -828,15 +828,16 @@ allows this user from this machine
****************************************************************************/
static BOOL check_user_equiv(char *user, char *remote, char *equiv_file)
{
- pstring buf;
int plus_allowed = 1;
char *file_host;
char *file_user;
- FILE *fp = sys_fopen(equiv_file, "r");
+ char **lines = file_lines_load(equiv_file, NULL);
+ int i;
+
DEBUG(5, ("check_user_equiv %s %s %s\n", user, remote, equiv_file));
- if (! fp) return False;
- while(fgets(buf, sizeof(buf), fp))
- {
+ if (! lines) return False;
+ for (i=0; lines[i]; i++) {
+ char *buf = lines[i];
trim_string(buf," "," ");
if (buf[0] != '#' && buf[0] != '\n')
@@ -857,7 +858,7 @@ static BOOL check_user_equiv(char *user, char *remote, char *equiv_file)
{
/* a bare plus means everbody allowed */
DEBUG(6, ("check_user_equiv everybody allowed\n"));
- fclose(fp);
+ file_lines_free(lines);
return True;
}
}
@@ -912,17 +913,17 @@ static BOOL check_user_equiv(char *user, char *remote, char *equiv_file)
/* is it this user */
if (file_user == 0 || strequal(user, file_user))
{
- fclose(fp);
DEBUG(5, ("check_user_equiv matched %s%s %s\n",
(plus ? "+" : "-"), file_host,
(file_user ? file_user : "")));
+ file_lines_free(lines);
return (plus ? True : False);
}
}
}
}
}
- fclose(fp);
+ file_lines_free(lines);
return False;
}