summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/client/client.c19
-rw-r--r--source3/include/includes.h25
-rw-r--r--source3/include/proto.h15
-rw-r--r--source3/include/smb.h15
-rw-r--r--source3/lib/util.c231
-rw-r--r--source3/locking/shmem.c4
-rw-r--r--source3/nmbd/nmbd.c5
-rw-r--r--source3/param/loadparm.c6
-rw-r--r--source3/smbd/dir.c32
-rw-r--r--source3/smbd/quotas.c4
-rw-r--r--source3/smbd/reply.c20
-rw-r--r--source3/smbd/server.c65
-rw-r--r--source3/smbd/trans2.c2
13 files changed, 269 insertions, 174 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index dd739fdfa5..c52815c25b 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -845,7 +845,7 @@ else
if( offset >= rdrcnt )
{
- DEBUG(1,("bad char ptr: datap=%u, converter=%u, rdata=%u, rdrcnt=%d>", datap, converter, (unsigned)rdata, rdrcnt));
+ DEBUG(1,("bad char ptr: datap=%u, converter=%u, rdata=%lu, rdrcnt=%d>", datap, converter, (unsigned long)rdata, rdrcnt));
return "<ERROR>";
}
else
@@ -3689,8 +3689,13 @@ try and browse available connections on a host
static BOOL browse_host(BOOL sort)
{
#ifdef NOSTRCASECMP
+/* If strcasecmp is already defined, remove it. */
+#ifdef strcasecmp
+#undef strcasecmp
+#endif /* strcasecmp */
#define strcasecmp StrCaseCmp
-#endif
+#endif /* NOSTRCASECMP */
+
extern int strcasecmp();
char *rparam = NULL;
@@ -4190,13 +4195,11 @@ static void wait_keyboard(char *buffer)
#else
{
char ch;
- int f_flags;
int readret;
-
- f_flags = fcntl(fileno(stdin), F_GETFL, 0);
- fcntl( fileno(stdin), F_SETFL, f_flags | O_NONBLOCK);
+
+ set_blocking(fileno(stdin), False);
readret = read_data( fileno(stdin), &ch, 1);
- fcntl(fileno(stdin), F_SETFL, f_flags);
+ set_blocking(fileno(stdin), True);
if (readret == -1)
{
if (errno != EAGAIN)
@@ -4322,7 +4325,7 @@ static BOOL process(char *base_directory)
bzero(OutBuffer,smb_size);
/* display a prompt */
- DEBUG(1,("smb: %s> ", CNV_LANG(cur_dir)));
+ DEBUG(0,("smb: %s> ", CNV_LANG(cur_dir)));
fflush(dbf);
#ifdef CLIX
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 7dcff54286..35112ff70b 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -666,38 +666,35 @@ char *mktemp(char *); /* No standard include */
#include <locale.h>
#ifdef EVEREST
#include <unistd.h>
-#endif
+#endif /* EVEREST */
#ifdef NETGROUP
#include <rpcsvc/ypclnt.h>
-#endif
+#endif /* NETGROUP */
#ifdef SecureWare
#include <sys/security.h>
#include <sys/audit.h>
#include <prot.h>
#define crypt bigcrypt
-#endif
-#ifndef EVEREST
- #define ftruncate(f,l) syscall(0x0a28,f,l)
-#endif
+#endif /* SecureWare */
#define SIGNAL_CAST (void (*)(int))
#define USE_WAITPID
#define USE_GETCWD
#define USE_SETSID
#ifdef SCO3_2_2
-#define NO_EID
-#else
+#define setuid(u) setreuid(u,-1)
+#define seteuid(u) setreuid(-1,u)
+#else /* SCO3_2_2 */
#ifndef EVEREST
+#define ftruncate(f,l) syscall(0x0a28,f,l)
#define USE_IFREQ
-#endif
-#endif
+#define NO_INITGROUPS
+#endif /* EVEREST */
+#endif /* SCO3_2_2 */
#define STATFS4
#define NO_FSYNC
-#ifndef EVEREST
-#define NO_INITGROUPS
-#endif
#define HAVE_PATHCONF
#define NO_GETRLIMIT
-#endif
+#endif /* SCO */
diff --git a/source3/include/proto.h b/source3/include/proto.h
index e9994214fb..6d248e2333 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -74,13 +74,13 @@ void dptr_closecnum(int cnum);
void dptr_idlecnum(int cnum);
void dptr_closepath(char *path,int pid);
int dptr_create(int cnum,char *path, BOOL expect_close,int pid);
-BOOL dptr_fill(int snum, char *buf1,unsigned int key);
+BOOL dptr_fill(char *buf1,unsigned int key);
BOOL dptr_zero(char *buf);
-void *dptr_fetch(int snum, char *buf,int *num);
-void *dptr_fetch_lanman2(int snum, char *params,int dptr_num);
-BOOL dir_check_ftype(int cnum,int mode,struct stat *st,int dirtype);
+void *dptr_fetch(char *buf,int *num);
+void *dptr_fetch_lanman2(char *params,int dptr_num);
+BOOL dir_check_ftype(int cnum, int mode,struct stat *st,int dirtype);
BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend);
-void *OpenDir(int snum, char *name, BOOL use_veto);
+void *OpenDir(int cnum, char *name, BOOL use_veto);
void CloseDir(void *p);
char *ReadDirName(void *p);
BOOL SeekDir(void *p,int pos);
@@ -954,8 +954,9 @@ char *gidtoname(int gid);
void BlockSignals(BOOL block,int signum);
void ajt_panic(void);
char *readdirname(void *p);
-BOOL is_hidden_path(int snum, char *name);
-BOOL is_vetoed_name(int snum, char *name);
+BOOL is_in_path(char *name, name_compare_entry *namelist);
+void set_namearray(name_compare_entry **ppname_array, char *namelist);
+void free_namearray(name_compare_entry *name_array);
BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type);
int file_lock(char *name,int timeout);
void file_unlock(int fd);
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 1d53942fa7..c7ff549fe5 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -339,6 +339,12 @@ struct uid_cache {
typedef struct
{
+ char *name;
+ BOOL is_wild;
+} name_compare_entry;
+
+typedef struct
+{
int service;
BOOL force_user;
struct uid_cache uid_cache;
@@ -363,6 +369,8 @@ typedef struct
time_t lastused;
BOOL used;
int num_files_open;
+ name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
+ name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
} connection_struct;
@@ -483,6 +491,7 @@ struct connect_record
#define VALID_CNUM(cnum) (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
#define OPEN_CNUM(cnum) (VALID_CNUM(cnum) && Connections[cnum].open)
#define IS_IPC(cnum) (VALID_CNUM(cnum) && Connections[cnum].ipc)
+#define IS_PRINT(cnum) (VALID_CNUM(cnum) && Connections[cnum].printer)
#define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
#define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
@@ -512,6 +521,9 @@ struct connect_record
#define MAP_HIDDEN(cnum) (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
#define MAP_SYSTEM(cnum) (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
#define MAP_ARCHIVE(cnum) (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
+#define IS_HIDDEN_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].hide_list))
+#define IS_VETO_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].veto_list))
+
#ifdef SMB_PASSWD
#define SMBENCRYPT() (lp_encrypted_passwords())
#else
@@ -916,7 +928,4 @@ enum case_handling {CASE_LOWER,CASE_UPPER};
/* Size of buffer to use when moving files across filesystems. */
#define COPYBUF_SIZE (8*1024)
-/* service-based parameter - files are not visible, but are accessible */
-#define DEFAULT_FILES_TO_HIDE ".*"
-
/* _SMB_H */
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 0d7c32be89..cec25ef9b9 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1721,7 +1721,7 @@ else
if SYSV use O_NDELAY
if BSD use FNDELAY
****************************************************************************/
-int set_blocking(int fd, int set)
+int set_blocking(int fd, BOOL set)
{
int val;
#ifdef O_NONBLOCK
@@ -2925,7 +2925,7 @@ int open_socket_out(int type, struct in_addr *addr, int port ,int timeout)
sock_out.sin_family = PF_INET;
/* set it non-blocking */
- set_blocking(res,0);
+ set_blocking(res,False);
DEBUG(3,("Connecting to %s at port %d\n",inet_ntoa(*addr),port));
@@ -2961,7 +2961,7 @@ connect_again:
}
/* set it blocking again */
- set_blocking(res,1);
+ set_blocking(res,True);
return res;
}
@@ -3193,48 +3193,44 @@ char *client_addr(void)
/*******************************************************************
sub strings with useful parameters
+Rewritten by Stefaan A Eeckels <Stefaan.Eeckels@ecc.lu> and
+Paul Rippin <pr3245@nopc.eurostat.cec.be>
********************************************************************/
-void standard_sub_basic(char *s)
+void standard_sub_basic(char *string)
{
- if (!strchr(s,'%')) return;
-
- string_sub(s,"%R",remote_proto);
- string_sub(s,"%a",remote_arch);
- string_sub(s,"%m",remote_machine);
- string_sub(s,"%L",local_machine);
-
- if (!strchr(s,'%')) return;
-
- string_sub(s,"%v",VERSION);
- string_sub(s,"%h",myhostname);
- string_sub(s,"%U",sesssetup_user);
-
- if (!strchr(s,'%')) return;
-
- string_sub(s,"%I",client_addr());
- if (strstr(s,"%M"))
- string_sub(s,"%M",client_name());
- string_sub(s,"%T",timestring());
-
- if (!strchr(s,'%')) return;
-
- {
- char pidstr[10];
- sprintf(pidstr,"%d",(int)getpid());
- string_sub(s,"%d",pidstr);
- }
-
- if (!strchr(s,'%')) return;
+ char *s, *p;
+ char pidstr[10];
+ struct passwd *pass;
+ for (s = string ; (p = strchr(s,'%')) != NULL ; s = p )
{
- struct passwd *pass = Get_Pwnam(sesssetup_user,False);
- if (pass) {
- string_sub(s,"%G",gidtoname(pass->pw_gid));
+ switch (*(p+1))
+ {
+ case 'G' : if ((pass = Get_Pwnam(sesssetup_user,False))!=NULL)
+ string_sub(p,"%G",gidtoname(pass->pw_gid));
+ else
+ p += 2;
+ break;
+ case 'I' : string_sub(p,"%I",client_addr()); break;
+ case 'L' : string_sub(p,"%L",local_machine); break;
+ case 'M' : string_sub(p,"%M",client_name()); break;
+ case 'R' : string_sub(p,"%R",remote_proto); break;
+ case 'T' : string_sub(p,"%T",timestring()); break;
+ case 'U' : string_sub(p,"%U",sesssetup_user); break;
+ case 'a' : string_sub(p,"%a",remote_arch); break;
+ case 'd' : sprintf(pidstr,"%d",(int)getpid());
+ string_sub(p,"%d",pidstr);
+ break;
+ case 'h' : string_sub(p,"%h",myhostname); break;
+ case 'm' : string_sub(p,"%m",remote_machine); break;
+ case 'v' : string_sub(p,"%v",VERSION); break;
+ case '\0' : p++; break; /* don't run off end if last character is % */
+ default : p+=2; break;
}
}
+ return;
}
-
/*******************************************************************
are two IPs on the same subnet?
********************************************************************/
@@ -3455,24 +3451,21 @@ char *readdirname(void *p)
}
/*
- * Utility function used by is_hidden_path() and is_vetoed_name()
- * to decide if the last component of a path matches a (possibly
- * wildcarded) entry in a namelist.
+ * Utility function used to decide if the last component
+ * of a path matches a (possibly wildcarded) entry in a namelist.
*/
-static BOOL is_in_path(char *name, char *namelist)
+BOOL is_in_path(char *name, name_compare_entry *namelist)
{
pstring last_component;
char *p;
- char *nameptr = namelist;
- char *name_end;
- DEBUG(5, ("is_in_path: %s list: %s\n", name, namelist));
+ DEBUG(5, ("is_in_path: %s\n", name));
/* if we have no list it's obviously not in the path */
- if((nameptr == NULL ) || ((nameptr != NULL) && (*nameptr == '\0')))
+ if((namelist == NULL ) || ((namelist != NULL) && (namelist[0].name == NULL)))
{
- DEBUG(5,("is_in_path: no name list. return False\n"));
+ DEBUG(5,("is_in_path: no name list.\n"));
return False;
}
@@ -3481,33 +3474,62 @@ static BOOL is_in_path(char *name, char *namelist)
strncpy(last_component, p ? p : name, sizeof(last_component)-1);
last_component[sizeof(last_component)-1] = '\0';
- /* now, we need to find the names one by one and check them
- they can contain spaces and all sorts of stuff so we
- separate them with of all things '\' which can never be in a filename
- I could use "" but then I have to break them all out
- maybe such a routine exists somewhere?
- */
-
- /* lkcl 03jul97 - the separator character used to be a '/'.
- i changed it to a '\', after examining the code, and seeing
- that unix_convert is called before check_path and dos_mode.
- unix_convert changes, in the path, all dos '\'s to unix '/'s.
+ for(; namelist->name != NULL; namelist++)
+ {
+ if(namelist->is_wild)
+ {
+ /* look for a wildcard match. */
+ if (mask_match(last_component, namelist->name, case_sensitive, False))
+ {
+ DEBUG(5,("is_in_path: mask match succeeded\n"));
+ return True;
+ }
+ }
+ else
+ {
+ if((case_sensitive && (strcmp(last_component, namelist->name) == 0))||
+ (!case_sensitive && (StrCaseCmp(last_component, namelist->name) == 0)))
+ {
+ DEBUG(5,("is_in_path: match succeeded\n"));
+ return True;
+ }
+ }
+ }
+ DEBUG(5,("is_in_path: match not found\n"));
- the alternatives are:
+ return False;
+}
- 1) move all check_path and dos_mode calls to before the
- unix_convert calls.
+/*
+ * Strip a '/' separated list into an array of
+ * name_compare_enties structures suitable for
+ * passing to is_in_path(). We do this for
+ * speed so we can pre-parse all the names in the list
+ * and don't do it for each call to is_in_path().
+ * namelist is modified here and is assumed to be
+ * a copy owned by the caller.
+ * We also check if the entry contains a wildcard to
+ * remove a potentially expensive call to mask_match
+ * if possible.
+ */
- 2) have a corresponding dos_convert call, which can be used
- in here to reverse '/'s into '\'s and vice-versa. users
- would specify the lp_veto_files and lp_hide_files parameters
- in dos mode path format ('\' for directory separator), with a
- list separator of '/', and they would be swapped inside this
- function, before making the search.
+void set_namearray(name_compare_entry **ppname_array, char *namelist)
+{
+ char *name_end;
+ char *nameptr = namelist;
+ int num_entries = 0;
+ int i;
- */
+ (*ppname_array) = NULL;
+
+ if((nameptr == NULL ) || ((nameptr != NULL) && (*nameptr == '\0')))
+ return;
- while (*nameptr)
+ /* We need to make two passes over the string. The
+ first to count the number of elements, the second
+ to split it.
+ */
+ while (*nameptr )
{
if ( *nameptr == '/' )
{
@@ -3516,42 +3538,79 @@ static BOOL is_in_path(char *name, char *namelist)
continue;
}
/* find the next / */
- if ((name_end = strchr(nameptr,'/')) != NULL)
+ name_end = strchr(nameptr, '/');
+
+ /* oops - the last check for a / didn't find one. */
+ if (name_end == NULL)
+ break;
+
+ /* next segment please */
+ nameptr = name_end + 1;
+ num_entries++;
+ }
+
+ if(num_entries == 0)
+ return;
+
+ if(( (*ppname_array) = (name_compare_entry *)malloc(
+ (num_entries + 1) * sizeof(name_compare_entry))) == NULL)
+ {
+ DEBUG(0,("set_namearray: malloc fail\n"));
+ return;
+ }
+
+ /* Now copy out the names */
+ nameptr = namelist;
+ i = 0;
+ while(*nameptr)
+ {
+ if ( *nameptr == '/' )
{
- *name_end = 0;
+ /* cope with multiple (useless) /s) */
+ nameptr++;
+ continue;
}
-
- /* look for a match. */
- if (mask_match(last_component, nameptr, case_sensitive, False))
+ /* find the next / */
+ if ((name_end = strchr(nameptr, '/')) != NULL)
{
- DEBUG(5,("is_in_path: mask match succeeded\n"));
- return True;
+ *name_end = 0;
}
/* oops - the last check for a / didn't find one. */
if (name_end == NULL)
+ break;
+
+ (*ppname_array)[i].is_wild = ((strchr( nameptr, '?')!=NULL) ||
+ (strchr( nameptr, '*')!=NULL));
+ if(((*ppname_array)[i].name = strdup(nameptr)) == NULL)
{
- DEBUG(5,("is_in_path: last name. failed\n"));
- return False;
+ DEBUG(0,("set_namearray: malloc fail (1)\n"));
+ return;
}
/* next segment please */
nameptr = name_end + 1;
+ i++;
}
-
- DEBUG(5,("is_in_path: not found\n"));
- return False;
-}
+ (*ppname_array)[i].name = NULL;
-BOOL is_hidden_path(int snum, char *name)
-{
- return is_in_path(name, lp_hide_files(snum));
+ return;
}
-BOOL is_vetoed_name(int snum, char *name)
+/****************************************************************************
+routine to free a namearray.
+****************************************************************************/
+
+void free_namearray(name_compare_entry *name_array)
{
- return is_in_path(name, lp_veto_files(snum));
+ if(name_array == 0)
+ return;
+
+ if(name_array->name != NULL)
+ free(name_array->name);
+
+ free((char *)name_array);
}
/****************************************************************************
diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c
index f3f84ec8c3..fcd9f3ad0d 100644
--- a/source3/locking/shmem.c
+++ b/source3/locking/shmem.c
@@ -167,7 +167,7 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
int smb_shm_processes_fd = -1;
int nb_read;
pid_t other_pid;
- int seek_back = -sizeof(other_pid);
+ int seek_back = -((int)sizeof(other_pid));
int free_slot = -1;
int erased_slot;
@@ -236,7 +236,7 @@ static BOOL smb_shm_unregister_process(char *processreg_file, pid_t pid)
int smb_shm_processes_fd = -1;
int nb_read;
pid_t other_pid;
- int seek_back = -sizeof(other_pid);
+ int seek_back = -((int)sizeof(other_pid));
int erased_slot;
BOOL found = False;
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 14611dc2c5..10701c24d4 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -529,7 +529,10 @@ static void usage(char *pname)
char buf[20];
if ((fd = open(pidFile,
- O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0)
+#ifdef O_NONBLOCK
+ O_NONBLOCK |
+#endif
+ O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0)
{
DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno)));
exit(1);
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 89595caa0d..ede1f12dec 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -270,7 +270,7 @@ static service sDefault =
NULL, /* szService */
NULL, /* szPath */
NULL, /* szUsername */
- NULL, /* szGuestAccount */
+ NULL, /* szGuestAccount - this is set in init_globals() */
NULL, /* szInvalidUsers */
NULL, /* szValidUsers */
NULL, /* szAdminUsers */
@@ -286,7 +286,7 @@ static service sDefault =
NULL, /* szLppausecommand */
NULL, /* szLpresumecommand */
NULL, /* szPrintername */
- NULL, /* szPrinterDriver */
+ NULL, /* szPrinterDriver - this is set in init_globals() */
NULL, /* szDontdescend */
NULL, /* szHostsallow */
NULL, /* szHostsdeny */
@@ -294,7 +294,7 @@ static service sDefault =
NULL, /* szMagicOutput */
NULL, /* szMangledMap */
NULL, /* szVetoFiles */
- DEFAULT_FILES_TO_HIDE, /* szHideFiles */
+ NULL, /* szHideFiles */
NULL, /* comment */
NULL, /* force user */
NULL, /* force group */
diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 2a219e0281..5bd5b1d573 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -108,18 +108,20 @@ static void dptr_idleoldest(void)
/****************************************************************************
get the dir ptr for a dir index
****************************************************************************/
-static void *dptr_get(int snum, int key,uint32 lastused)
+static void *dptr_get(int key,uint32 lastused)
{
- if (dirptrs[key].valid) {
- if (lastused) dirptrs[key].lastused = lastused;
- if (!dirptrs[key].ptr) {
+ struct dptr_struct *dp = &dirptrs[key];
+
+ if (dp->valid) {
+ if (lastused) dp->lastused = lastused;
+ if (!dp->ptr) {
if (dptrs_open >= MAXDIR)
dptr_idleoldest();
DEBUG(4,("Reopening dptr key %d\n",key));
- if ((dirptrs[key].ptr = OpenDir(snum, dirptrs[key].path, True)))
+ if ((dp->ptr = OpenDir(dp->cnum, dp->path, True)))
dptrs_open++;
}
- return(dirptrs[key].ptr);
+ return(dp->ptr);
}
return(NULL);
}
@@ -259,7 +261,7 @@ static BOOL start_dir(int cnum,char *directory)
if (! *directory)
directory = ".";
- Connections[cnum].dirptr = OpenDir(SNUM(cnum), directory, True);
+ Connections[cnum].dirptr = OpenDir(cnum, directory, True);
if (Connections[cnum].dirptr) {
dptrs_open++;
string_set(&Connections[cnum].dirpath,directory);
@@ -345,10 +347,10 @@ int dptr_create(int cnum,char *path, BOOL expect_close,int pid)
/****************************************************************************
fill the 5 byte server reserved dptr field
****************************************************************************/
-BOOL dptr_fill(int snum, char *buf1,unsigned int key)
+BOOL dptr_fill(char *buf1,unsigned int key)
{
unsigned char *buf = (unsigned char *)buf1;
- void *p = dptr_get(snum, key,0);
+ void *p = dptr_get(key,0);
uint32 offset;
if (!p) {
DEBUG(1,("filling null dirptr %d\n",key));
@@ -373,10 +375,10 @@ BOOL dptr_zero(char *buf)
/****************************************************************************
fetch the dir ptr and seek it given the 5 byte server field
****************************************************************************/
-void *dptr_fetch(int snum, char *buf,int *num)
+void *dptr_fetch(char *buf,int *num)
{
unsigned int key = *(unsigned char *)buf;
- void *p = dptr_get(snum, key,dircounter++);
+ void *p = dptr_get(key,dircounter++);
uint32 offset;
if (!p) {
DEBUG(3,("fetched null dirptr %d\n",key));
@@ -393,9 +395,9 @@ void *dptr_fetch(int snum, char *buf,int *num)
/****************************************************************************
fetch the dir ptr and seek it given the lanman2 parameter block
****************************************************************************/
-void *dptr_fetch_lanman2(int snum, char *params,int dptr_num)
+void *dptr_fetch_lanman2(char *params,int dptr_num)
{
- void *p = dptr_get(snum, dptr_num,dircounter++);
+ void *p = dptr_get(dptr_num,dircounter++);
uint32 resume_key = SVAL(params,6);
BOOL uses_resume_key = BITSETW(params+10,2);
BOOL continue_bit = BITSETW(params+10,3);
@@ -520,7 +522,7 @@ typedef struct
/*******************************************************************
open a directory
********************************************************************/
-void *OpenDir(int snum, char *name, BOOL use_veto)
+void *OpenDir(int cnum, char *name, BOOL use_veto)
{
Dir *dirp;
char *n;
@@ -541,7 +543,7 @@ void *OpenDir(int snum, char *name, BOOL use_veto)
int l = strlen(n)+1;
/* If it's a vetoed file, pretend it doesn't even exist */
- if (use_veto && is_vetoed_name(snum, n)) continue;
+ if (use_veto && IS_VETO_PATH(cnum, n)) continue;
if (used + l > dirp->mallocsize) {
int s = MAX(used+l,used+2000);
diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c
index 8cbe46d9e1..883c2c050d 100644
--- a/source3/smbd/quotas.c
+++ b/source3/smbd/quotas.c
@@ -331,8 +331,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize)
ret = quotactl(Q_GETQUOTA, name, euser_id, &D);
#endif
- setuid(user_id); /* Restore the original UID status */
- seteuid(euser_id);
+ seteuid(euser_id); /* Restore the original uid status. */
+ setuid(user_id);
if (ret < 0) {
DEBUG(2,("disk_quotas ioctl (Solaris) failed\n"));
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 5869588664..374a01b665 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -771,7 +771,7 @@ int reply_search(char *inbuf,char *outbuf)
memcpy(mask,status+1,11);
mask[11] = 0;
dirtype = CVAL(status,0) & 0x1F;
- Connections[cnum].dirptr = dptr_fetch(SNUM(cnum), status+12,&dptr_num);
+ Connections[cnum].dirptr = dptr_fetch(status+12,&dptr_num);
if (!Connections[cnum].dirptr)
goto SearchEmpty;
string_set(&Connections[cnum].dirpath,dptr_path(dptr_num));
@@ -836,7 +836,7 @@ int reply_search(char *inbuf,char *outbuf)
{
memcpy(p,status,21);
make_dir_struct(p,"???????????",volume_label(SNUM(cnum)),0,aVOLID,0);
- dptr_fill(SNUM(cnum), p+12,dptr_num);
+ dptr_fill(p+12,dptr_num);
if (dptr_zero(p+12) && (status_len==0))
numentries = 1;
else
@@ -858,7 +858,7 @@ int reply_search(char *inbuf,char *outbuf)
{
memcpy(p,status,21);
make_dir_struct(p,mask,fname,size,mode,date);
- dptr_fill(SNUM(cnum), p+12,dptr_num);
+ dptr_fill(p+12,dptr_num);
numentries++;
}
p += DIR_STRUCT_SIZE;
@@ -941,7 +941,7 @@ int reply_fclose(char *inbuf,char *outbuf)
memcpy(status,smb_buf(inbuf) + 1 + strlen(path) + 4,21);
- if(dptr_fetch(SNUM(cnum), status+12,&dptr_num)) {
+ if(dptr_fetch(status+12,&dptr_num)) {
/* Close the dptr - we know it's gone */
dptr_close(dptr_num);
}
@@ -1323,7 +1323,7 @@ int reply_unlink(char *inbuf,char *outbuf)
char *dname;
if (check_name(directory,cnum))
- dirptr = OpenDir(SNUM(cnum), directory, True);
+ dirptr = OpenDir(cnum, directory, True);
/* XXXX the CIFS spec says that if bit0 of the flags2 field is set then
the pattern matches against the long name, otherwise the short name
@@ -2457,7 +2457,7 @@ int reply_rmdir(char *inbuf,char *outbuf)
do a recursive delete) then fail the rmdir. */
BOOL all_veto_files = True;
char *dname;
- void *dirptr = OpenDir(SNUM(cnum), directory, False);
+ void *dirptr = OpenDir(cnum, directory, False);
if(dirptr != NULL)
{
@@ -2466,7 +2466,7 @@ int reply_rmdir(char *inbuf,char *outbuf)
{
if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
continue;
- if(!is_vetoed_name(SNUM(cnum), dname))
+ if(!IS_VETO_PATH(cnum, dname))
{
all_veto_files = False;
break;
@@ -2733,7 +2733,7 @@ int reply_mv(char *inbuf,char *outbuf)
pstring destname;
if (check_name(directory,cnum))
- dirptr = OpenDir(SNUM(cnum), directory, True);
+ dirptr = OpenDir(cnum, directory, True);
if (dirptr)
{
@@ -2924,7 +2924,7 @@ int reply_copy(char *inbuf,char *outbuf)
pstring destname;
if (check_name(directory,cnum))
- dirptr = OpenDir(SNUM(cnum), directory, True);
+ dirptr = OpenDir(cnum, directory, True);
if (dirptr)
{
@@ -3105,7 +3105,7 @@ int reply_readbmpx(char *inbuf,char *outbuf,int length,int bufsize)
mincount = SVAL(inbuf,smb_vwv4);
data = smb_buf(outbuf);
- pad = ((int)data)%4;
+ pad = ((long)data)%4;
if (pad) pad = 4 - pad;
data += pad;
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 3c5cd6bea7..30a3027de9 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -226,7 +226,7 @@ int dos_mode(int cnum,char *path,struct stat *sbuf)
/* Optimization : Only call is_hidden_path if it's not already
hidden. */
- if (!(result & aHIDDEN) && is_hidden_path(SNUM(cnum), path))
+ if (!(result & aHIDDEN) && IS_HIDDEN_PATH(cnum,path))
{
result |= aHIDDEN;
}
@@ -358,7 +358,7 @@ scan a directory to find a filename, matching without case sensitivity
If the name looks like a mangled name then try via the mangling functions
****************************************************************************/
-static BOOL scan_directory(char *path, char *name,int snum,BOOL docache)
+static BOOL scan_directory(char *path, char *name,int cnum,BOOL docache)
{
void *cur_dir;
char *dname;
@@ -371,7 +371,7 @@ static BOOL scan_directory(char *path, char *name,int snum,BOOL docache)
if (*path == 0)
path = ".";
- if (docache && (dname = DirCacheCheck(path,name,snum))) {
+ if (docache && (dname = DirCacheCheck(path,name,SNUM(cnum)))) {
strcpy(name, dname);
return(True);
}
@@ -380,7 +380,7 @@ static BOOL scan_directory(char *path, char *name,int snum,BOOL docache)
check_mangled_stack(name);
/* open the directory */
- if (!(cur_dir = OpenDir(snum, path, True)))
+ if (!(cur_dir = OpenDir(cnum, path, True)))
{
DEBUG(3,("scan dir didn't open dir [%s]\n",path));
return(False);
@@ -394,13 +394,13 @@ static BOOL scan_directory(char *path, char *name,int snum,BOOL docache)
continue;
strcpy(name2,dname);
- if (!name_map_mangle(name2,False,snum)) continue;
+ if (!name_map_mangle(name2,False,SNUM(cnum))) continue;
if ((mangled && mangled_equal(name,name2))
|| fname_equal(name, dname))
{
/* we've found the file, change it's name and return */
- if (docache) DirCacheAdd(path,name,dname,snum);
+ if (docache) DirCacheAdd(path,name,dname,SNUM(cnum));
strcpy(name, dname);
CloseDir(cur_dir);
return(True);
@@ -533,7 +533,7 @@ BOOL unix_convert(char *name,int cnum,pstring saved_last_component)
/* try to find this part of the path in the directory */
if (strchr(start,'?') || strchr(start,'*') ||
- !scan_directory(dirpath, start, SNUM(cnum), end?True:False))
+ !scan_directory(dirpath, start, cnum, end?True:False))
{
if (end)
{
@@ -810,7 +810,7 @@ BOOL check_name(char *name,int cnum)
errno = 0;
- if( is_vetoed_name(SNUM(cnum), name))
+ if( IS_VETO_PATH(cnum, name))
{
DEBUG(5,("file path name %s vetoed\n",name));
return(0);
@@ -2485,6 +2485,8 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de
pcon->printer = (strncmp(dev,"LPT",3) == 0);
pcon->ipc = (strncmp(dev,"IPC",3) == 0);
pcon->dirptr = NULL;
+ pcon->veto_list = NULL;
+ pcon->hide_list = NULL;
string_set(&pcon->dirpath,"");
string_set(&pcon->user,user);
@@ -2627,6 +2629,13 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de
/* we've finished with the sensitive stuff */
unbecome_user();
+ /* Add veto/hide lists */
+ if (!IS_IPC(cnum) && !IS_PRINT(cnum))
+ {
+ set_namearray( &pcon->veto_list, lp_veto_files(SNUM(cnum)));
+ set_namearray( &pcon->hide_list, lp_hide_files(SNUM(cnum)));
+ }
+
{
DEBUG(IS_IPC(cnum)?3:1,("%s %s (%s) connect to service %s as user %s (uid=%d,gid=%d) (pid %d)\n",
timestring(),
@@ -3176,6 +3185,9 @@ void close_cnum(int cnum, uint16 vuid)
Connections[cnum].ngroups = 0;
}
+ free_namearray(Connections[cnum].veto_list);
+ free_namearray(Connections[cnum].hide_list);
+
string_set(&Connections[cnum].user,"");
string_set(&Connections[cnum].dirpath,"");
string_set(&Connections[cnum].connectpath,"");
@@ -3440,22 +3452,28 @@ void exit_server(char *reason)
/****************************************************************************
do some standard substitutions in a string
****************************************************************************/
-void standard_sub(int cnum,char *s)
+void standard_sub(int cnum,char *string)
{
- if (!strchr(s,'%')) return;
-
- if (VALID_CNUM(cnum))
- {
- string_sub(s,"%S",lp_servicename(Connections[cnum].service));
- string_sub(s,"%P",Connections[cnum].connectpath);
- string_sub(s,"%u",Connections[cnum].user);
- if (strstr(s,"%H")) {
- char *home = get_home_dir(Connections[cnum].user);
- if (home) string_sub(s,"%H",home);
+ if (VALID_CNUM(cnum)) {
+ char *p, *s, *home;
+
+ for ( s=string ; (p=strchr(s, '%')) != NULL ; s=p ) {
+ switch (*(p+1)) {
+ case 'H' : if ((home = get_home_dir(Connections[cnum].user))!=NULL)
+ string_sub(p,"%H",home);
+ else
+ p += 2;
+ break;
+ case 'P' : string_sub(p,"%P",Connections[cnum].connectpath); break;
+ case 'S' : string_sub(p,"%S",lp_servicename(Connections[cnum].service)); break;
+ case 'g' : string_sub(p,"%g",gidtoname(Connections[cnum].gid)); break;
+ case 'u' : string_sub(p,"%u",Connections[cnum].user); break;
+ case '\0' : p++; break; /* don't run off the end of the string */
+ default : p+=2; break;
}
- string_sub(s,"%g",gidtoname(Connections[cnum].gid));
}
- standard_sub_basic(s);
+ }
+ standard_sub_basic(string);
}
/*
@@ -4267,7 +4285,10 @@ static void usage(char *pname)
char buf[20];
if ((fd = open(pidFile,
- O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0)
+#ifdef O_NONBLOCK
+ O_NONBLOCK |
+#endif
+ O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0)
{
DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno)));
exit(1);
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index 1b199f01ba..11a2a50ffe 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -782,7 +782,7 @@ static int call_trans2findnext(char *inbuf, char *outbuf, int length, int bufsiz
return(ERROR(ERRDOS,ERRnomem));
/* Check that the dptr is valid */
- if(!(Connections[cnum].dirptr = dptr_fetch_lanman2(SNUM(cnum), params, dptr_num)))
+ if(!(Connections[cnum].dirptr = dptr_fetch_lanman2(params, dptr_num)))
return(ERROR(ERRDOS,ERRnofiles));
string_set(&Connections[cnum].dirpath,dptr_path(dptr_num));