summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1996-08-15 15:11:34 +0000
committerAndrew Tridgell <tridge@samba.org>1996-08-15 15:11:34 +0000
commit47673b32ed4a907b380b70d5f4f366ba8be301d2 (patch)
tree384a13167ec3b96d217acce3e6add82e391d1246 /source3
parent7ea7a3361320c4c25e6bb80c1ed763c229fa541a (diff)
downloadsamba-47673b32ed4a907b380b70d5f4f366ba8be301d2.tar.gz
samba-47673b32ed4a907b380b70d5f4f366ba8be301d2.tar.bz2
samba-47673b32ed4a907b380b70d5f4f366ba8be301d2.zip
- added FAST_SHARE_MODES code
- added some named pipe code from Jim (This used to be commit c94866e9e44ea1eb72da06bc65ef1c032ae8e0c9)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/includes.h8
-rw-r--r--source3/include/proto.h34
-rw-r--r--source3/include/smb.h26
-rw-r--r--source3/lib/util.c16
-rw-r--r--source3/locking/locking.c246
-rw-r--r--source3/locking/shmem.c722
-rw-r--r--source3/namelogon.c21
-rw-r--r--source3/nmbd/nmbd.c10
-rw-r--r--source3/script/mkproto.awk2
-rw-r--r--source3/smbd/ipc.c108
-rw-r--r--source3/smbd/pipes.c363
-rw-r--r--source3/smbd/reply.c18
-rw-r--r--source3/smbd/server.c23
-rw-r--r--source3/utils/status.c177
14 files changed, 1689 insertions, 85 deletions
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 3057531f7f..fd468abc07 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -183,7 +183,7 @@
#endif
#endif
-#if USE_MMAP
+#if defined(USE_MMAP) || defined(FAST_SHARE_MODES)
#include <sys/mman.h>
#endif
@@ -223,7 +223,7 @@ Here come some platform specific sections
#define USE_SETSID
#define HAVE_BZERO
#define HAVE_MEMMOVE
-#define USE_SIGBLOCK
+#define USE_SIGPROCMASK
#if 0
/* SETFS disabled until we can check on some bug reports */
#if _LINUX_C_LIB_VERSION_MAJOR >= 5
@@ -259,7 +259,7 @@ typedef unsigned short mode_t;
#endif
#define REPLACE_GETPASS
#define BSD_TERMIO
-#define USE_SIGBLOCK
+#define USE_SIGPROCMASK
#endif
@@ -293,7 +293,7 @@ extern int innetgr (const char *, const char *, const char *, const char *);
#define USE_GETCWD
#define USE_SETSID
#define REPLACE_GETPASS
-#define USE_SIGBLOCK
+#define USE_SIGPROCMASK
#endif
diff --git a/source3/include/proto.h b/source3/include/proto.h
index dd9413605f..04f5ef158d 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -259,12 +259,14 @@ void file_unlock(int fd);
BOOL is_locked(int fnum,int cnum,uint32 count,uint32 offset);
BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
+BOOL start_share_mode_mgmt(void);
+BOOL stop_share_mode_mgmt(void);
int get_share_mode_by_fnum(int cnum,int fnum,int *pid);
int get_share_mode_byname(int cnum,char *fname,int *pid);
int get_share_mode(int cnum,struct stat *sbuf,int *pid);
void del_share_mode(int fnum);
BOOL set_share_mode(int fnum,int mode);
-void clean_share_files(void);
+void clean_share_modes(void);
/*The following definitions come from mangle.c */
@@ -545,6 +547,18 @@ BOOL server_validate(char *buf);
BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname);
void pcap_printer_fn(void (*fn)());
+/*The following definitions come from pipes.c */
+
+int reply_open_pipe_and_X(char *inbuf,char *outbuf,int length,int bufsize);
+BOOL api_LsarpcSNPHS(int cnum,int uid, char *param,char *data,
+ int mdrcnt,int mprcnt,
+ char **rdata,char **rparam,
+ int *rdata_len,int *rparam_len);
+BOOL api_LsarpcTNP(int cnum,int uid, char *param,char *data,
+ int mdrcnt,int mprcnt,
+ char **rdata,char **rparam,
+ int *rdata_len,int *rparam_len);
+
/*The following definitions come from predict.c */
int read_predict(int fd,int offset,char *buf,char **ptr,int num);
@@ -674,6 +688,22 @@ char *smb_fn_name(int type);
int chain_reply(int type,char *inbuf,char *inbuf2,char *outbuf,char *outbuf2,int size,int bufsize);
int construct_reply(char *inbuf,char *outbuf,int size,int bufsize);
+/*The following definitions come from shmem.c */
+
+BOOL shm_open( char *file_name, int size);
+BOOL shm_close( void );
+shm_offset_t shm_alloc(int size);
+BOOL shm_free(shm_offset_t offset);
+shm_offset_t shm_get_userdef_off(void);
+BOOL shm_set_userdef_off(shm_offset_t userdef_off);
+void * shm_offset2addr(shm_offset_t offset);
+shm_offset_t shm_addr2offset(void *addr);
+BOOL shm_lock(void);
+BOOL shm_unlock(void);
+BOOL shm_get_usage(int *bytes_free,
+ int *bytes_used,
+ int *bytes_overhead);
+
/*The following definitions come from smbencrypt.c */
void str_to_key(uchar *str,uchar *key);
@@ -876,7 +906,7 @@ struct hostent *Get_Hostbyname(char *name);
BOOL process_exists(int pid);
char *uidtoname(int uid);
char *gidtoname(int gid);
-void BlockSignals(BOOL block);
+void BlockSignals(BOOL block,int signum);
void ajt_panic(void);
char *readdirname(void *p);
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 317f31b19e..c9180dd50c 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -36,8 +36,9 @@
#define BUFFER_SIZE (0xFFFF)
#define SAFETY_MARGIN 1024
-#ifndef EXTERN
-# define EXTERN extern
+/* size of shared memory used for share mode locking */
+#ifndef SHMEM_SIZE
+#define SHMEM_SIZE 102400
#endif
#define NMB_PORT 137
@@ -53,6 +54,11 @@
typedef int BOOL;
+/* offset in shared memory */
+typedef int shm_offset_t;
+#define NULL_OFFSET (shm_offset_t)(0)
+
+
/*
Samba needs type definitions for int16, int32, uint16 and uint32.
@@ -106,7 +112,7 @@ typedef unsigned int uint32;
#ifndef SYSLOG
#define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
#else
-EXTERN int syslog_level;
+extern int syslog_level;
#define DEBUG(level,body) ((DEBUGLEVEL>=(level))? (syslog_level = (level), Debug1 body):0)
#endif
@@ -395,6 +401,20 @@ struct interface
struct in_addr nmask;
};
+/* share mode record in shared memory */
+typedef struct
+{
+ shm_offset_t next_offset; /* offset of next record in list in shared mem */
+ int locking_version;
+ int share_mode;
+ time_t time;
+ int pid;
+ dev_t st_dev;
+ ino_t st_ino;
+ char file_name[1]; /* dynamically allocated with correct size */
+} share_mode_record;
+
+
/* this is used for smbstatus */
struct connect_record
{
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 413f1c648e..5b765e0ac6 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3118,16 +3118,20 @@ char *gidtoname(int gid)
/*******************************************************************
block sigs
********************************************************************/
-void BlockSignals(BOOL block)
+void BlockSignals(BOOL block,int signum)
{
#ifdef USE_SIGBLOCK
- int block_mask = (sigmask(SIGTERM)|sigmask(SIGQUIT)|sigmask(SIGSEGV)
- |sigmask(SIGCHLD)|sigmask(SIGQUIT)|sigmask(SIGBUS)|
- sigmask(SIGINT));
+ int block_mask = sigmask(signum);
+ static int oldmask = 0;
if (block)
- sigblock(block_mask);
+ oldmask = sigblock(block_mask);
else
- sigsetmask(0);
+ sigsetmask(oldmask);
+#elif defined(USE_SIGPROCMASK)
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set,signum);
+ sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL);
#endif
}
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 8f76ce43da..60428f2e98 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -17,6 +17,11 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ Revision History:
+
+ 12 aug 96: Erik.Devriendt@te6.siemens.be
+ added support for shared memory implementation of share mode locking
*/
#include "includes.h"
@@ -226,6 +231,34 @@ BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *
return True; /* Did unlock */
}
+#ifdef FAST_SHARE_MODES
+/*******************************************************************
+ initialize the shared memory for share_mode management
+ ******************************************************************/
+BOOL start_share_mode_mgmt(void)
+{
+ pstring shmem_file_name;
+
+ strcpy(shmem_file_name,lp_lockdir());
+ trim_string(shmem_file_name,"","/");
+ if (!*shmem_file_name) return(False);
+ strcat(shmem_file_name, "/SHARE_MEM_FILE");
+ return shm_open(shmem_file_name, SHMEM_SIZE);
+}
+
+
+/*******************************************************************
+ deinitialize the shared memory for share_mode management
+ ******************************************************************/
+BOOL stop_share_mode_mgmt(void)
+{
+ return shm_close();
+}
+
+#else
+
+/* SHARE MODE LOCKS USING SLOW DESCRIPTION FILES */
+
/*******************************************************************
name a share file
******************************************************************/
@@ -251,6 +284,7 @@ static BOOL share_name_fnum(int fnum,char *name)
return(share_name(Files[fnum].cnum,&st,name));
}
+#endif
/*******************************************************************
get the share mode of a file using the fnum
@@ -278,6 +312,78 @@ get the share mode of a file
********************************************************************/
int get_share_mode(int cnum,struct stat *sbuf,int *pid)
{
+#ifdef FAST_SHARE_MODES
+ share_mode_record *scanner_p;
+ share_mode_record *prev_p;
+ int ret;
+ BOOL found = False;
+
+ *pid = 0;
+
+ if(!shm_lock()) return (0);
+
+ scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off());
+ prev_p = scanner_p;
+ while(scanner_p)
+ {
+ if( (scanner_p->st_dev == sbuf->st_dev) && (scanner_p->st_ino == sbuf->st_ino) )
+ {
+ found = True;
+ break;
+ }
+ else
+ {
+ prev_p = scanner_p ;
+ scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset);
+ }
+ }
+
+ if(!found)
+ {
+ shm_unlock();
+ return (0);
+ }
+
+ if(scanner_p->locking_version != LOCKING_VERSION)
+ {
+ DEBUG(2,("Deleting old share mode record due to old locking version %d",scanner_p->locking_version));
+ if(prev_p == scanner_p)
+ shm_set_userdef_off(scanner_p->next_offset);
+ else
+ prev_p->next_offset = scanner_p->next_offset;
+ shm_free(shm_addr2offset(scanner_p));
+ *pid = 0;
+
+ shm_unlock();
+ return (0);
+ }
+
+ *pid = scanner_p->pid;
+ ret = scanner_p->share_mode;
+
+ if (*pid && !process_exists(*pid))
+ {
+ ret = 0;
+ *pid = 0;
+ }
+
+ if (! *pid)
+ {
+ if(prev_p == scanner_p)
+ shm_set_userdef_off(scanner_p->next_offset);
+ else
+ prev_p->next_offset = scanner_p->next_offset;
+ shm_free(shm_addr2offset(scanner_p));
+ }
+
+ if (*pid)
+ DEBUG(5,("Read share mode record mode 0x%X pid=%d\n",ret,*pid));
+
+ if(!shm_unlock()) return (0);
+
+ return(ret);
+
+#else
pstring fname;
int fd2;
char buf[16];
@@ -319,6 +425,7 @@ int get_share_mode(int cnum,struct stat *sbuf,int *pid)
DEBUG(5,("Read share file %s mode 0x%X pid=%d\n",fname,ret,*pid));
return(ret);
+#endif
}
@@ -327,6 +434,67 @@ del the share mode of a file, if we set it last
********************************************************************/
void del_share_mode(int fnum)
{
+#ifdef FAST_SHARE_MODES
+ struct stat st;
+ time_t t=0;
+ int pid=0;
+ BOOL del = False;
+ share_mode_record *scanner_p;
+ share_mode_record *prev_p;
+ BOOL found = False;
+
+
+
+ if (fstat(Files[fnum].fd,&st) != 0) return;
+
+ if (!shm_lock()) return;
+
+ scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off());
+ prev_p = scanner_p;
+ while(scanner_p)
+ {
+ if( (scanner_p->st_dev == st.st_dev) && (scanner_p->st_ino == st.st_ino) )
+ {
+ found = True;
+ break;
+ }
+ else
+ {
+ prev_p = scanner_p ;
+ scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset);
+ }
+ }
+
+ if(!found)
+ {
+ shm_unlock();
+ return;
+ }
+
+ t = scanner_p->time;
+ pid = scanner_p->pid;
+
+ if( (scanner_p->locking_version != LOCKING_VERSION) || !pid || !process_exists(pid))
+ del = True;
+
+ if (!del && t == Files[fnum].open_time && pid==(int)getpid())
+ del = True;
+
+ if (del)
+ {
+ DEBUG(2,("Deleting share mode record\n"));
+ if(prev_p == scanner_p)
+ shm_set_userdef_off(scanner_p->next_offset);
+ else
+ prev_p->next_offset = scanner_p->next_offset;
+ shm_free(shm_addr2offset(scanner_p));
+
+ }
+
+ shm_unlock();
+ return;
+
+#else
pstring fname;
int fd2;
char buf[16];
@@ -363,6 +531,7 @@ void del_share_mode(int fnum)
strcpy(share_del_pending,fname);
}
}
+#endif
}
@@ -371,6 +540,36 @@ set the share mode of a file
********************************************************************/
BOOL set_share_mode(int fnum,int mode)
{
+#ifdef FAST_SHARE_MODES
+ int pid = (int)getpid();
+ struct stat st;
+ shm_offset_t new_off;
+ share_mode_record *new_p;
+
+
+ if (fstat(Files[fnum].fd,&st) != 0) return(False);
+
+ if (!shm_lock()) return (False);
+ new_off = shm_alloc(sizeof(share_mode_record) + strlen(Files[fnum].name) );
+ if (new_off == NULL_OFFSET) return (False);
+ new_p = (share_mode_record *)shm_offset2addr(new_off);
+ new_p->locking_version = LOCKING_VERSION;
+ new_p->share_mode = mode;
+ new_p->time = Files[fnum].open_time;
+ new_p->pid = pid;
+ new_p->st_dev = st.st_dev;
+ new_p->st_ino = st.st_ino;
+ strcpy(new_p->file_name,Files[fnum].name);
+ new_p->next_offset = shm_get_userdef_off();
+ shm_set_userdef_off(new_off);
+
+
+ DEBUG(3,("Created share record for %s with mode 0x%X pid=%d\n",Files[fnum].name,mode,pid));
+
+ if (!shm_unlock()) return (False);
+ return(True);
+
+#else
pstring fname;
int fd2;
char buf[16];
@@ -406,14 +605,58 @@ BOOL set_share_mode(int fnum,int mode)
DEBUG(3,("Created share file %s with mode 0x%X pid=%d\n",fname,mode,pid));
return(True);
+#endif
}
/*******************************************************************
cleanup any stale share files
********************************************************************/
-void clean_share_files(void)
+void clean_share_modes(void)
{
+#ifdef USE_SHMEM
+ share_mode_record *scanner_p;
+ share_mode_record *prev_p;
+ int pid;
+
+ if (!shm_lock()) return;
+
+ scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off());
+ prev_p = scanner_p;
+ while(scanner_p)
+ {
+ pid = scanner_p->pid;
+
+ if( (scanner_p->locking_version != LOCKING_VERSION) || !process_exists(pid))
+ {
+ DEBUG(2,("Deleting stale share mode record"));
+ if(prev_p == scanner_p)
+ {
+ shm_set_userdef_off(scanner_p->next_offset);
+ shm_free(shm_addr2offset(scanner_p));
+ scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off());
+ prev_p = scanner_p;
+ }
+ else
+ {
+ prev_p->next_offset = scanner_p->next_offset;
+ shm_free(shm_addr2offset(scanner_p));
+ scanner_p = (share_mode_record *)shm_offset2addr(prev_p->next_offset);
+ }
+
+ }
+ else
+ {
+ prev_p = scanner_p ;
+ scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset);
+ }
+ }
+
+
+ shm_unlock();
+ return;
+
+#else
char *lockdir = lp_lockdir();
void *dir;
char *s;
@@ -457,4 +700,5 @@ void clean_share_files(void)
}
closedir(dir);
+#endif
}
diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c
new file mode 100644
index 0000000000..3a308d07ba
--- /dev/null
+++ b/source3/locking/shmem.c
@@ -0,0 +1,722 @@
+/*
+ Unix SMB/Netbios implementation.
+ Version 1.9.
+ Shared memory functions
+ Copyright (C) Erik Devriendt 1996
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifdef FAST_SHARE_MODES
+
+
+#include "includes.h"
+
+extern int DEBUGLEVEL;
+
+
+#define SHM_MAGIC 0x53484100
+/* = "SHM" in hex */
+
+#define SHM_VERSION 1
+
+/* WARNING : offsets are used because mmap() does not guarantee that all processes have the
+ shared memory mapped to the same address */
+
+struct ShmHeader
+{
+ int shm_magic;
+ int shm_version;
+ int total_size; /* in bytes */
+ BOOL consistent;
+ shm_offset_t first_free_off;
+ shm_offset_t userdef_off; /* a userdefined offset. can be used to store root of tree or list */
+ struct { /* a cell is a range of bytes of sizeof(struct ShmBlockDesc) size */
+ int cells_free;
+ int cells_used;
+ int cells_system; /* number of cells used as allocated block descriptors */
+ } statistics;
+};
+
+#define SHM_NOT_FREE_OFF (-1)
+struct ShmBlockDesc
+{
+ shm_offset_t next; /* offset of next block in the free list or SHM_NOT_FREE_OFF when block in use */
+ int size; /* user size in BlockDescSize units */
+};
+
+#define EOList_Addr (struct ShmBlockDesc *)( 0 )
+#define EOList_Off (NULL_OFFSET)
+
+#define CellSize sizeof(struct ShmBlockDesc)
+
+/* HeaderSize aligned on 8 byte boundary */
+#define AlignedHeaderSize ((sizeof(struct ShmHeader)+7) & ~7)
+
+static int shm_fd = -1;
+static pstring shm_processreg_name = "";
+
+static struct ShmHeader *shm_header_p = (struct ShmHeader *)0;
+static int shm_times_locked = 0;
+
+static BOOL shm_register_process(char *processreg_file, pid_t pid, BOOL *other_processes)
+{
+ int old_umask;
+ int shm_processes_fd = -1;
+ int nb_read;
+ pid_t other_pid;
+ int free_slot = -1;
+ int erased_slot;
+
+
+ old_umask = umask(0);
+ shm_processes_fd = open(processreg_file, O_RDWR | O_CREAT, 0666);
+ umask(old_umask);
+ if ( shm_processes_fd < 0 )
+ {
+ DEBUG(0,("ERROR shm_register_process : processreg_file open failed with code %d\n",errno));
+ return False;
+ }
+
+ *other_processes = False;
+
+ while ((nb_read = read(shm_processes_fd, &other_pid, sizeof(other_pid))) > 0)
+ {
+ if(other_pid)
+ {
+ if(process_exists(other_pid))
+ *other_processes = True;
+ else
+ {
+ /* erase old pid */
+ DEBUG(2,("shm_register_process : erasing stale record for pid %d\n",other_pid));
+ other_pid = (pid_t)0;
+ erased_slot = lseek(shm_processes_fd, -sizeof(other_pid), SEEK_CUR);
+ write(shm_processes_fd, &other_pid, sizeof(other_pid));
+ if(free_slot < 0)
+ free_slot = erased_slot;
+ }
+ }
+ else
+ if(free_slot < 0)
+ free_slot = lseek(shm_processes_fd, -sizeof(other_pid), SEEK_CUR);
+ }
+ if (nb_read < 0)
+ {
+ DEBUG(0,("ERROR shm_register_process : processreg_file read failed with code %d\n",errno));
+ close(shm_processes_fd);
+ return False;
+ }
+
+ if(free_slot < 0)
+ free_slot = lseek(shm_processes_fd, 0, SEEK_END);
+
+ DEBUG(2,("shm_register_process : writing record for pid %d at offset %d\n",pid,free_slot));
+ lseek(shm_processes_fd, free_slot, SEEK_SET);
+ if(write(shm_processes_fd, &pid, sizeof(pid)) < 0)
+ {
+ DEBUG(0,("ERROR shm_register_process : processreg_file write failed with code %d\n",errno));
+ close(shm_processes_fd);
+ return False;
+ }
+
+ close(shm_processes_fd);
+
+ return True;
+}
+
+static BOOL shm_unregister_process(char *processreg_file, pid_t pid)
+{
+ int old_umask;
+ int shm_processes_fd = -1;
+ int nb_read;
+ pid_t other_pid;
+ int erased_slot;
+ BOOL found = False;
+
+
+ old_umask = umask(0);
+ shm_processes_fd = open(processreg_file, O_RDWR);
+ umask(old_umask);
+ if ( shm_processes_fd < 0 )
+ {
+ DEBUG(0,("ERROR shm_unregister_process : processreg_file open failed with code %d\n",errno));
+ return False;
+ }
+
+ while ((nb_read = read(shm_processes_fd, &other_pid, sizeof(other_pid))) > 0)
+ {
+ if(other_pid == pid)
+ {
+ /* erase pid */
+ DEBUG(2,("shm_unregister_process : erasing record for pid %d\n",other_pid));
+ other_pid = (pid_t)0;
+ erased_slot = lseek(shm_processes_fd, -sizeof(other_pid), SEEK_CUR);
+ if(write(shm_processes_fd, &other_pid, sizeof(other_pid)) < 0)
+ {
+ DEBUG(0,("ERROR shm_unregister_process : processreg_file write failed with code %d\n",errno));
+ close(shm_processes_fd);
+ return False;
+ }
+
+ found = True;
+ break;
+ }
+ }
+ if (nb_read < 0)
+ {
+ DEBUG(0,("ERROR shm_unregister_process : processreg_file read failed with code %d\n",errno));
+ close(shm_processes_fd);
+ return False;
+ }
+
+ if(!found)
+ {
+ DEBUG(0,("ERROR shm_unregister_process : couldn't find pid %d in file %s\n",pid,processreg_file));
+ close(shm_processes_fd);
+ return False;
+ }
+
+
+ close(shm_processes_fd);
+
+ return True;
+}
+
+
+static BOOL shm_validate_header(int size)
+{
+ if( !shm_header_p )
+ {
+ /* not mapped yet */
+ DEBUG(0,("ERROR shm_validate_header : shmem not mapped\n"));
+ return False;
+ }
+
+ if(shm_header_p->shm_magic != SHM_MAGIC)
+ {
+ DEBUG(0,("ERROR shm_validate_header : bad magic\n"));
+ return False;
+ }
+ if(shm_header_p->shm_version != SHM_VERSION)
+ {
+ DEBUG(0,("ERROR shm_validate_header : bad version %X\n",shm_header_p->shm_version));
+ return False;
+ }
+
+ if(shm_header_p->total_size != size)
+ {
+ DEBUG(0,("ERROR shm_validate_header : shmem size mismatch (old = %d, new = %d)\n",shm_header_p->total_size,size));
+ return False;
+ }
+
+ if(!shm_header_p->consistent)
+ {
+ DEBUG(0,("ERROR shm_validate_header : shmem not consistent\n"));
+ return False;
+ }
+ return True;
+}
+
+static BOOL shm_initialize(int size)
+{
+ struct ShmBlockDesc * first_free_block_p;
+
+ DEBUG(2,("shm_initialize : initializing shmem file of size %d\n",size));
+
+ if( !shm_header_p )
+ {
+ /* not mapped yet */
+ DEBUG(0,("ERROR shm_initialize : shmem not mapped\n"));
+ return False;
+ }
+
+ shm_header_p->shm_magic = SHM_MAGIC;
+ shm_header_p->shm_version = SHM_VERSION;
+ shm_header_p->total_size = size;
+ shm_header_p->first_free_off = AlignedHeaderSize;
+ shm_header_p->userdef_off = NULL_OFFSET;
+
+ first_free_block_p = (struct ShmBlockDesc *)shm_offset2addr(shm_header_p->first_free_off);
+ first_free_block_p->next = EOList_Off;
+ first_free_block_p->size = ( size - AlignedHeaderSize - CellSize ) / CellSize ;
+
+ shm_header_p->statistics.cells_free = first_free_block_p->size;
+ shm_header_p->statistics.cells_used = 0;
+ shm_header_p->statistics.cells_system = 1;
+
+ shm_header_p->consistent = True;
+
+ return True;
+}
+
+static void shm_solve_neighbors(struct ShmBlockDesc *head_p )
+{
+ struct ShmBlockDesc *next_p;
+
+ /* Check if head_p and head_p->next are neighbors and if so join them */
+ if ( head_p == EOList_Addr ) return ;
+ if ( head_p->next == EOList_Off ) return ;
+
+ next_p = (struct ShmBlockDesc *)shm_offset2addr(head_p->next);
+ if ( ( head_p + head_p->size + 1 ) == next_p)
+ {
+ head_p->size += next_p->size +1 ; /* adapt size */
+ head_p->next = next_p->next ; /* link out */
+
+ shm_header_p->statistics.cells_free += 1;
+ shm_header_p->statistics.cells_system -= 1;
+ }
+}
+
+
+
+BOOL shm_open( char *file_name, int size)
+{
+ int filesize;
+ BOOL created_new = False;
+ BOOL other_processes = True;
+ int old_umask;
+
+ DEBUG(2,("shm_open : using shmem file %s to be of size %d\n",file_name,size));
+
+ old_umask = umask(0);
+ shm_fd = open(file_name, O_RDWR | O_CREAT, 0666);
+ umask(old_umask);
+ if ( shm_fd < 0 )
+ {
+ DEBUG(0,("ERROR shm_open : open failed with code %d\n",errno));
+ return False;
+ }
+
+ if (!shm_lock())
+ {
+ DEBUG(0,("ERROR shm_open : can't do shm_lock\n"));
+ return False;
+ }
+
+ if( (filesize = lseek(shm_fd, 0, SEEK_END)) < 0)
+ {
+ DEBUG(0,("ERROR shm_open : lseek failed with code %d\n",errno));
+ shm_unlock();
+ close(shm_fd);
+ return False;
+ }
+
+ /* return the file offset to 0 to save on later seeks */
+ lseek(shm_fd,0,SEEK_SET);
+
+ if (filesize == 0)
+ {
+ /* we just created a new one */
+ created_new = True;
+ }
+
+ /* to find out if some other process is already mapping the file,
+ we use a registration file containing the processids of the file mapping processes
+ */
+
+ /* construct processreg file name */
+ strcpy(shm_processreg_name, file_name);
+ strcat(shm_processreg_name, ".processes");
+
+ if (! shm_register_process(shm_processreg_name, getpid(), &other_processes))
+ {
+ shm_unlock();
+ close(shm_fd);
+ return False;
+ }
+
+ if (created_new || !other_processes)
+ {
+ /* we just created a new one, or are the first opener, lets set it size */
+ if( ftruncate(shm_fd, size) <0)
+ {
+ DEBUG(0,("ERROR shm_open : ftruncate failed with code %d\n",errno));
+ shm_unregister_process(shm_processreg_name, getpid());
+ shm_unlock();
+ close(shm_fd);
+ return False;
+ }
+
+ /* paranoia */
+ lseek(shm_fd,0,SEEK_SET);
+
+ filesize = size;
+ }
+
+ if (size != filesize )
+ {
+ /* the existing file has a different size and we are not the first opener.
+ Since another process is still using it, we will use the file size */
+ DEBUG(0,("WARNING shm_open : filesize (%d) != expected size (%d), using filesize\n",filesize,size));
+ size = filesize;
+ }
+
+ shm_header_p = (struct ShmHeader *)mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, shm_fd, 0);
+ /* WARNING, shm_header_p can be different for different processes mapping the same file ! */
+ if (shm_header_p == (struct ShmHeader *)(-1))
+ {
+ DEBUG(0,("ERROR shm_open : mmap failed with code %d\n",errno));
+ shm_unregister_process(shm_processreg_name, getpid());
+ shm_unlock();
+ close(shm_fd);
+ return False;
+ }
+
+
+ if (created_new || !other_processes)
+ {
+ shm_initialize(size);
+ }
+ else if (!shm_validate_header(size) )
+ {
+ /* existing file is corrupt, samba admin should remove it by hand */
+ DEBUG(0,("ERROR shm_open : corrupt shared mem file, remove it manually\n"));
+ munmap((caddr_t)shm_header_p, size);
+ shm_unregister_process(shm_processreg_name, getpid());
+ shm_unlock();
+ close(shm_fd);
+ return False;
+ }
+
+ shm_unlock();
+ return True;
+
+}
+
+
+BOOL shm_close( void )
+{
+
+ DEBUG(2,("shm_close\n"));
+ if(shm_times_locked > 0)
+ DEBUG(0,("WARNING shm_close : shmem was still locked %d times\n",shm_times_locked));;
+ if ( munmap((caddr_t)shm_header_p, shm_header_p->total_size) < 0)
+ {
+ DEBUG(0,("ERROR shm_close : munmap failed with code %d\n",errno));
+ }
+
+ shm_lock();
+ shm_unregister_process(shm_processreg_name, getpid());
+ shm_unlock();
+
+ close(shm_fd);
+
+ shm_fd = -1;
+ shm_processreg_name[0] = '\0';
+
+ shm_header_p = (struct ShmHeader *)0;
+ shm_times_locked = 0;
+
+ return True;
+}
+
+shm_offset_t shm_alloc(int size)
+{
+ unsigned num_cells ;
+ struct ShmBlockDesc *scanner_p;
+ struct ShmBlockDesc *prev_p;
+ struct ShmBlockDesc *new_p;
+ shm_offset_t result_offset;
+
+
+ if( !shm_header_p )
+ {
+ /* not mapped yet */
+ DEBUG(0,("ERROR shm_alloc : shmem not mapped\n"));
+ return NULL_OFFSET;
+ }
+
+ if( !shm_header_p->consistent)
+ {
+ DEBUG(0,("ERROR shm_alloc : shmem not consistent\n"));
+ return NULL_OFFSET;
+ }
+
+
+ /* calculate the number of cells */
+ num_cells = (size + CellSize -1) / CellSize;
+
+ /* set start of scan */
+ prev_p = (struct ShmBlockDesc *)shm_offset2addr(shm_header_p->first_free_off);
+ scanner_p = prev_p ;
+
+ /* scan the free list to find a matching free space */
+ while ( ( scanner_p != EOList_Addr ) && ( scanner_p->size < num_cells ) )
+ {
+ prev_p = scanner_p;
+ scanner_p = (struct ShmBlockDesc *)shm_offset2addr(scanner_p->next);
+ }
+
+ /* at this point scanner point to a block header or to the end of the list */
+ if ( scanner_p == EOList_Addr )
+ {
+ DEBUG(0,("ERROR shm_alloc : alloc of %d bytes failed, no free space found\n",size));
+ return (NULL_OFFSET);
+ }
+
+ /* going to modify shared mem */
+ shm_header_p->consistent = False;
+
+ /* if we found a good one : scanner == the good one */
+ if ( scanner_p->size <= num_cells + 2 )
+ {
+ /* there is no use in making a new one, it will be too small anyway
+ * we will link out scanner
+ */
+ if ( prev_p == scanner_p )
+ {
+ shm_header_p->first_free_off = scanner_p->next ;
+ }
+ else
+ {
+ prev_p->next = scanner_p->next ;
+ }
+ shm_header_p->statistics.cells_free -= scanner_p->size;
+ shm_header_p->statistics.cells_used += scanner_p->size;
+ }
+ else
+ {
+ /* Make a new one */
+ new_p = scanner_p + 1 + num_cells;
+ new_p->size = scanner_p->size - num_cells - 1;
+ new_p->next = scanner_p->next;
+ scanner_p->size = num_cells;
+ scanner_p->next = shm_addr2offset(new_p);
+
+ if ( prev_p != scanner_p )
+ {
+ prev_p->next = shm_addr2offset(new_p) ;
+ }
+ else
+ {
+ shm_header_p->first_free_off = shm_addr2offset(new_p) ;
+ }
+ shm_header_p->statistics.cells_free -= num_cells+1;
+ shm_header_p->statistics.cells_used += num_cells;
+ shm_header_p->statistics.cells_system += 1;
+ }
+
+ result_offset = shm_addr2offset( &(scanner_p[1]) );
+ scanner_p->next = SHM_NOT_FREE_OFF ;
+
+ /* end modification of shared mem */
+ shm_header_p->consistent = True;
+
+ DEBUG(2,("shm_alloc : request for %d bytes, allocated %d bytes at offset %d\n",size,scanner_p->size*CellSize,result_offset ));
+
+ return ( result_offset );
+}
+
+
+
+BOOL shm_free(shm_offset_t offset)
+{
+ struct ShmBlockDesc *header_p ; /* pointer to header of block to free */
+ struct ShmBlockDesc *scanner_p ; /* used to scan the list */
+ struct ShmBlockDesc *prev_p ; /* holds previous in the list */
+
+ if( !shm_header_p )
+ {
+ /* not mapped yet */
+ DEBUG(0,("ERROR shm_free : shmem not mapped\n"));
+ return False;
+ }
+
+ if( !shm_header_p->consistent)
+ {
+ DEBUG(0,("ERROR shm_free : shmem not consistent\n"));
+ return False;
+ }
+
+ header_p = ( (struct ShmBlockDesc *)shm_offset2addr(offset) - 1); /* make pointer to header of block */
+
+ if (header_p->next != SHM_NOT_FREE_OFF)
+ {
+ DEBUG(0,("ERROR shm_free : bad offset (%d)\n",offset));
+ return False;
+ }
+
+ /* find a place in the free_list to put the header in */
+
+ /* set scanner and previous pointer to start of list */
+ prev_p = (struct ShmBlockDesc *)shm_offset2addr(shm_header_p->first_free_off);
+ scanner_p = prev_p ;
+
+ while ( ( scanner_p != EOList_Addr) && (scanner_p < header_p) ) /* while we didn't scan past its position */
+ {
+ prev_p = scanner_p ;
+ scanner_p = (struct ShmBlockDesc *)shm_offset2addr(scanner_p->next);
+ }
+
+ shm_header_p->consistent = False;
+
+ DEBUG(2,("shm_free : freeing %d bytes at offset %d\n",header_p->size*CellSize,offset));
+
+ if ( scanner_p == prev_p )
+ {
+ shm_header_p->statistics.cells_free += header_p->size;
+ shm_header_p->statistics.cells_used -= header_p->size;
+
+ /* we must free it at the beginning of the list */
+ shm_header_p->first_free_off = shm_addr2offset(header_p); /* set the free_list_pointer to this block_header */
+
+ /* scanner is the one that was first in the list */
+ header_p->next = shm_addr2offset(scanner_p);
+ shm_solve_neighbors( header_p ); /* if neighbors then link them */
+
+ shm_header_p->consistent = True;
+ return True;
+ }
+ else
+ {
+ shm_header_p->statistics.cells_free += header_p->size;
+ shm_header_p->statistics.cells_used -= header_p->size;
+
+ prev_p->next = shm_addr2offset(header_p);
+ header_p->next = shm_addr2offset(scanner_p);
+ shm_solve_neighbors(header_p) ;
+ shm_solve_neighbors(prev_p) ;
+
+ shm_header_p->consistent = True;
+ return True;
+ }
+}
+
+shm_offset_t shm_get_userdef_off(void)
+{
+ if (!shm_header_p)
+ return NULL_OFFSET;
+ else
+ return shm_header_p->userdef_off;
+}
+
+BOOL shm_set_userdef_off(shm_offset_t userdef_off)
+{
+ if (!shm_header_p)
+ return False;
+ else
+ shm_header_p->userdef_off = userdef_off;
+ return True;
+}
+
+void * shm_offset2addr(shm_offset_t offset)
+{
+ if (offset == NULL_OFFSET )
+ return (void *)(0);
+
+ if (!shm_header_p)
+ return (void *)(0);
+
+ return (void *)((char *)shm_header_p + offset );
+}
+
+shm_offset_t shm_addr2offset(void *addr)
+{
+ if (!addr)
+ return NULL_OFFSET;
+
+ if (!shm_header_p)
+ return NULL_OFFSET;
+
+ return (shm_offset_t)((char *)addr - (char *)shm_header_p);
+}
+
+BOOL shm_lock(void)
+{
+ if (shm_fd < 0)
+ {
+ DEBUG(0,("ERROR shm_lock : bad shm_fd (%d)\n",shm_fd));
+ return False;
+ }
+
+ shm_times_locked++;
+
+ if(shm_times_locked > 1)
+ {
+ DEBUG(2,("shm_lock : locked %d times\n",shm_times_locked));
+ return True;
+ }
+
+ if (lockf(shm_fd, F_LOCK, 0) < 0)
+ {
+ DEBUG(0,("ERROR shm_lock : lockf failed with code %d\n",errno));
+ shm_times_locked--;
+ return False;
+ }
+
+ return True;
+
+}
+
+
+
+BOOL shm_unlock(void)
+{
+ if (shm_fd < 0)
+ {
+ DEBUG(0,("ERROR shm_unlock : bad shm_fd (%d)\n",shm_fd));
+ return False;
+ }
+
+ if(shm_times_locked == 0)
+ {
+ DEBUG(0,("ERROR shm_unlock : shmem not locked\n",shm_fd));
+ return False;
+ }
+
+ shm_times_locked--;
+
+ if(shm_times_locked > 0)
+ {
+ DEBUG(2,("shm_unlock : still locked %d times\n",shm_times_locked));
+ return True;
+ }
+
+ if (lockf(shm_fd, F_ULOCK, 0) < 0)
+ {
+ DEBUG(0,("ERROR shm_unlock : lockf failed with code %d\n",errno));
+ shm_times_locked++;
+ return False;
+ }
+
+ return True;
+
+}
+
+
+BOOL shm_get_usage(int *bytes_free,
+ int *bytes_used,
+ int *bytes_overhead)
+{
+ if( !shm_header_p )
+ {
+ /* not mapped yet */
+ DEBUG(0,("ERROR shm_free : shmem not mapped\n"));
+ return False;
+ }
+ *bytes_free = shm_header_p->statistics.cells_free * CellSize;
+ *bytes_used = shm_header_p->statistics.cells_used * CellSize;
+ *bytes_overhead = shm_header_p->statistics.cells_system * CellSize + AlignedHeaderSize;
+
+ return True;
+}
+
+#else /* FAST_SHARE_MODES */
+ int shmem_dummy_procedure(void)
+{return 0;}
+#endif
diff --git a/source3/namelogon.c b/source3/namelogon.c
index 24bb984247..c10049135c 100644
--- a/source3/namelogon.c
+++ b/source3/namelogon.c
@@ -49,7 +49,7 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len)
struct in_addr ip = dgram->header.source_ip;
struct subnet_record *d = find_subnet(ip);
char *logname,*q;
- char *reply_name;
+ fstring reply_name;
BOOL add_slashes = False;
pstring outbuf;
int code,reply_code;
@@ -78,7 +78,8 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len)
char *user = skip_string(machine,1);
logname = skip_string(user,1);
reply_code = 6;
- reply_name = myname;
+ strcpy(reply_name,myname);
+ strupper(reply_name);
add_slashes = True;
DEBUG(3,("Domain login request from %s(%s) user=%s\n",
machine,inet_ntoa(p->ip),user));
@@ -89,11 +90,12 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len)
char *machine = buf+2;
logname = skip_string(machine,1);
reply_code = 7;
- reply_name = lp_domain_controller();
+ strcpy(reply_name,lp_domain_controller());
if (!*reply_name) {
- reply_name = myname;
+ strcpy(reply_name,myname);
reply_code = 0xC;
}
+ strupper(reply_name);
DEBUG(3,("GETDC request from %s(%s), reporting %s 0x%2x\n",
machine,inet_ntoa(p->ip), reply_name, reply_code));
}
@@ -112,7 +114,6 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len)
q += 2;
}
StrnCpy(q,reply_name,16);
- strupper(q);
q = skip_string(q,1);
if (reply_code == 0xC)
@@ -122,13 +123,11 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len)
q++;
}
- StrnCpy(q,reply_name,16);
- strupper(q);
- q = skip_string(q,1);
+ PutUniCode(q,reply_name);
+ q += 2*(strlen(reply_name) + 1);
- StrnCpy(q,lp_workgroup(),16);
- strupper(q);
- q = skip_string(q,1);
+ PutUniCode(q,lp_workgroup());
+ q += 2*(strlen(lp_workgroup()) + 1);
SIVAL(q,0,1);
q += 4;
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 5c3be920f5..04751f6f56 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -58,7 +58,7 @@ extern struct in_addr ipzero;
****************************************************************************/
static int sig_term()
{
- BlockSignals(True);
+ BlockSignals(True,SIGTERM);
DEBUG(0,("Got SIGTERM: going down...\n"));
@@ -83,7 +83,7 @@ catch a sighup
****************************************************************************/
static int sig_hup(void)
{
- BlockSignals(True);
+ BlockSignals(True,SIGHUP);
DEBUG(0,("Got SIGHUP (reload not implemented)\n"));
dump_names();
@@ -91,7 +91,7 @@ static int sig_hup(void)
set_samba_nb_type();
- BlockSignals(False);
+ BlockSignals(False,SIGHUP);
#ifndef DONT_REINSTALL_SIG
signal(SIGHUP,SIGNAL_CAST sig_hup);
#endif
@@ -103,12 +103,12 @@ catch a sigpipe
****************************************************************************/
static int sig_pipe(void)
{
- BlockSignals(True);
+ BlockSignals(True,SIGPIPE);
DEBUG(0,("Got SIGPIPE\n"));
if (!is_daemon)
exit(1);
- BlockSignals(False);
+ BlockSignals(False,SIGPIPE);
return(0);
}
diff --git a/source3/script/mkproto.awk b/source3/script/mkproto.awk
index 200d5bd050..08b13d4610 100644
--- a/source3/script/mkproto.awk
+++ b/source3/script/mkproto.awk
@@ -64,7 +64,7 @@ BEGIN {
next;
}
-!/^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time/ {
+!/^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^shm_offset_t/ {
next;
}
diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c
index 5b3939e98c..39b8f3f089 100644
--- a/source3/smbd/ipc.c
+++ b/source3/smbd/ipc.c
@@ -59,11 +59,21 @@ extern fstring local_machine;
#define SNLEN 15 /* service name length */
#define QNLEN 12 /* queue name maximum length */
-#define MAJOR_VERSION 2
+#define MAJOR_VERSION 4
#define MINOR_VERSION 0
extern int Client;
+static BOOL api_Unsupported(int cnum,int uid, char *param,char *data,
+ int mdrcnt,int mprcnt,
+ char **rdata,char **rparam,
+ int *rdata_len,int *rparam_len);
+static BOOL api_TooSmall(int cnum,int uid, char *param,char *data,
+ int mdrcnt,int mprcnt,
+ char **rdata,char **rparam,
+ int *rdata_len,int *rparam_len);
+
+
static int CopyExpanded(int cnum, int snum, char** dst, char* src, int* n)
{
pstring buf;
@@ -1906,7 +1916,8 @@ static BOOL api_RNetUserGetInfo(int cnum,int uid, char *param,char *data,
p2 = skip_string(p2,1);
}
if (uLevel == 11) { /* modelled after NTAS 3.51 reply */
- SSVAL(p,34,USER_PRIV_USER); /* user privilege */
+ SSVAL(p,34,
+ Connections[cnum].admin_user?USER_PRIV_ADMIN:USER_PRIV_USER);
SIVAL(p,36,0); /* auth flags */
SIVALS(p,40,-1); /* password age */
SIVAL(p,44,PTR_DIFF(p2,p)); /* home dir */
@@ -1941,7 +1952,8 @@ static BOOL api_RNetUserGetInfo(int cnum,int uid, char *param,char *data,
if (uLevel == 1 || uLevel == 2) {
memset(p+22,' ',16); /* password */
SIVALS(p,38,-1); /* password age */
- SSVAL(p,42,USER_PRIV_ADMIN); /* user privilege */
+ SSVAL(p,42,
+ Connections[cnum].admin_user?USER_PRIV_ADMIN:USER_PRIV_USER);
SIVAL(p,44,PTR_DIFF(p2,*rdata)); /* home dir */
strcpy(p2,"\\\\%L\\HOMES");
standard_sub_basic(p2);
@@ -2577,6 +2589,92 @@ static BOOL api_WPrintPortEnum(int cnum,int uid, char *param,char *data,
return(True);
}
+
+struct
+{
+ char * name;
+ char * pipename;
+ int subcommand;
+ BOOL (*fn) ();
+} api_fd_commands [] =
+ {
+ { "SetNmdPpHndState", "lsarpc", 1, api_LsarpcSNPHS },
+ { "TransactNmPipe", "lsarpc", 0x26, api_LsarpcTNP },
+ { NULL, NULL, -1, api_Unsupported }
+ };
+
+/****************************************************************************
+ handle remote api calls delivered to a named pipe already opened.
+ ****************************************************************************/
+static int api_fd_reply(int cnum,int uid,char *outbuf,
+ uint16 *setup,char *data,char *params,
+ int suwcnt,int tdscnt,int tpscnt,int mdrcnt,int mprcnt)
+{
+ char *rdata = NULL;
+ char *rparam = NULL;
+ int rdata_len = 0;
+ int rparam_len = 0;
+ BOOL reply=False;
+ int i;
+ int fd;
+ int subcommand;
+
+ /* First find out the name of this file. */
+ if (suwcnt != 2)
+ {
+ DEBUG(0,("Unexpected named pipe transaction.\n"));
+ return(-1);
+ }
+
+ /* Get the file handle and hence the file name. */
+ fd = setup[1];
+ subcommand = setup[0];
+
+ DEBUG(3,("Got API command %d on pipe %s ",subcommand,Files[fd].name));
+ DEBUG(3,("(tdscnt=%d,tpscnt=%d,mdrcnt=%d,mprcnt=%d)\n",
+ tdscnt,tpscnt,mdrcnt,mprcnt));
+
+ for (i=0;api_fd_commands[i].name;i++)
+ if (strequal(api_fd_commands[i].pipename, Files[fd].name) &&
+ api_fd_commands[i].subcommand == subcommand &&
+ api_fd_commands[i].fn)
+ {
+ DEBUG(3,("Doing %s\n",api_fd_commands[i].name));
+ break;
+ }
+
+ rdata = (char *)malloc(1024); if (rdata) bzero(rdata,1024);
+ rparam = (char *)malloc(1024); if (rparam) bzero(rparam,1024);
+
+ reply = api_fd_commands[i].fn(cnum,uid,params,data,mdrcnt,mprcnt,
+ &rdata,&rparam,&rdata_len,&rparam_len);
+
+ if (rdata_len > mdrcnt ||
+ rparam_len > mprcnt)
+ {
+ reply = api_TooSmall(cnum,uid,params,data,mdrcnt,mprcnt,
+ &rdata,&rparam,&rdata_len,&rparam_len);
+ }
+
+
+ /* if we get False back then it's actually unsupported */
+ if (!reply)
+ api_Unsupported(cnum,uid,params,data,mdrcnt,mprcnt,
+ &rdata,&rparam,&rdata_len,&rparam_len);
+
+ /* now send the reply */
+ send_trans_reply(outbuf,rdata,rparam,NULL,rdata_len,rparam_len,0);
+
+ if (rdata)
+ free(rdata);
+ if (rparam)
+ free(rparam);
+
+ return(-1);
+}
+
+
+
/****************************************************************************
the buffer was too small
****************************************************************************/
@@ -2727,6 +2825,10 @@ static int named_pipe(int cnum,int uid, char *outbuf,char *name,
if (strequal(name,"LANMAN"))
return(api_reply(cnum,uid,outbuf,data,params,tdscnt,tpscnt,mdrcnt,mprcnt));
+if (strlen(name) < 1)
+ return(api_fd_reply(cnum,uid,outbuf,setup,data,params,suwcnt,tdscnt,tpscnt,mdrcnt,mprcnt));
+
+
DEBUG(3,("named pipe command on <%s> 0x%X setup1=%d\n",
name,(int)setup[0],(int)setup[1]));
diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c
new file mode 100644
index 0000000000..724f58e1e2
--- /dev/null
+++ b/source3/smbd/pipes.c
@@ -0,0 +1,363 @@
+/*
+ Unix SMB/Netbios implementation.
+ Version 1.9.
+ Pipe SMB reply routines
+ Copyright (C) Andrew Tridgell 1992-1995
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+/*
+ This file handles reply_ calls on named pipes that the server
+ makes to handle specific protocols
+*/
+
+
+#include "includes.h"
+#include "trans2.h"
+
+#define PIPE "\\PIPE\\"
+#define PIPELEN strlen(PIPE)
+
+#define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
+
+/* look in server.c for some explanation of these variables */
+extern int Protocol;
+extern int DEBUGLEVEL;
+extern int chain_size;
+extern int maxxmit;
+extern int chain_fnum;
+extern char magic_char;
+extern connection_struct Connections[];
+extern files_struct Files[];
+extern BOOL case_sensitive;
+extern pstring sesssetup_user;
+extern int Client;
+
+/* this macro should always be used to extract an fnum (smb_fid) from
+a packet to ensure chaining works correctly */
+#define GETFNUM(buf,where) (chain_fnum!= -1?chain_fnum:SVAL(buf,where))
+
+char * known_pipes [] =
+{
+ "lsarpc",
+ NULL
+};
+
+/****************************************************************************
+ reply to an open and X on a named pipe
+
+ In fact what we do is to open a regular file with the same name in
+ /tmp. This can then be closed as normal. Reading and writing won't
+ make much sense, but will do *something*. The real reason for this
+ support is to be able to do transactions on them (well, on lsarpc
+ for domain login purposes...).
+
+ This code is basically stolen from reply_open_and_X with some
+ wrinkles to handle pipes.
+****************************************************************************/
+int reply_open_pipe_and_X(char *inbuf,char *outbuf,int length,int bufsize)
+{
+ pstring fname;
+ int cnum = SVAL(inbuf,smb_tid);
+ int fnum = -1;
+ int outsize = 0;
+ int smb_com2 = CVAL(inbuf,smb_vwv0);
+ int smb_off2 = SVAL(inbuf,smb_vwv1);
+ int smb_mode = SVAL(inbuf,smb_vwv3);
+ int smb_attr = SVAL(inbuf,smb_vwv5);
+#if 0
+ int open_flags = SVAL(inbuf,smb_vwv2);
+ int smb_sattr = SVAL(inbuf,smb_vwv4);
+ uint32 smb_time = make_unix_date3(inbuf+smb_vwv6);
+#endif
+ int smb_ofun = SVAL(inbuf,smb_vwv8);
+ int unixmode;
+ int size=0,fmode=0,mtime=0,rmode=0;
+ struct stat sbuf;
+ int smb_action = 0;
+ int i;
+
+ /* XXXX we need to handle passed times, sattr and flags */
+ strcpy(fname,smb_buf(inbuf));
+
+ /* If the name doesn't start \PIPE\ then this is directed */
+ /* at a mailslot or something we really, really don't understand, */
+ /* not just something we really don't understand. */
+ if ( strncmp(fname,PIPE,PIPELEN) != 0 )
+ return(ERROR(ERRSRV,ERRaccess));
+
+ DEBUG(4,("Opening pipe %s.\n", fname));
+
+ /* Strip \PIPE\ off the name. */
+ strcpy(fname,smb_buf(inbuf) + PIPELEN);
+
+ /* See if it is one we want to handle. */
+ for( i = 0; known_pipes[i] ; i++ )
+ if( strcmp(fname,known_pipes[i]) == 0 )
+ break;
+
+ if ( known_pipes[i] == NULL )
+ return(ERROR(ERRSRV,ERRaccess));
+
+ /* Known pipes arrive with DIR attribs. Remove it so a regular file */
+ /* can be opened and add it in after the open. */
+ DEBUG(3,("Known pipe %s opening.\n",fname));
+ smb_attr &= ~aDIR;
+ Connections[cnum].read_only = 0;
+ smb_ofun |= 0x10; /* Add Create it not exists flag */
+
+ unix_convert(fname,cnum);
+
+ fnum = find_free_file();
+ if (fnum < 0)
+ return(ERROR(ERRSRV,ERRnofids));
+
+ if (!check_name(fname,cnum))
+ return(UNIXERROR(ERRDOS,ERRnoaccess));
+
+ unixmode = unix_mode(cnum,smb_attr);
+
+ open_file_shared(fnum,cnum,fname,smb_mode,smb_ofun,unixmode,
+ &rmode,&smb_action);
+
+ if (!Files[fnum].open)
+ return(UNIXERROR(ERRDOS,ERRnoaccess));
+
+ if (fstat(Files[fnum].fd,&sbuf) != 0) {
+ close_file(fnum);
+ return(ERROR(ERRDOS,ERRnoaccess));
+ }
+
+ size = sbuf.st_size;
+ fmode = dos_mode(cnum,fname,&sbuf);
+ mtime = sbuf.st_mtime;
+ if (fmode & aDIR) {
+ close_file(fnum);
+ return(ERROR(ERRDOS,ERRnoaccess));
+ }
+
+ /* Prepare the reply */
+ outsize = set_message(outbuf,15,0,True);
+ CVAL(outbuf,smb_vwv0) = smb_com2;
+
+ /* Put things back the way they were. */
+ Connections[cnum].read_only = 1;
+
+ /* Mark the opened file as an existing named pipe in message mode. */
+ SSVAL(outbuf,smb_vwv9,2);
+ SSVAL(outbuf,smb_vwv10,0xc700);
+ if (rmode == 2)
+ {
+ DEBUG(4,("Resetting open result to open from create.\n"));
+ rmode = 1;
+ }
+
+ SSVAL(outbuf,smb_vwv1,(chain_size+outsize)-4);
+ SSVAL(outbuf,smb_vwv2,fnum);
+ SSVAL(outbuf,smb_vwv3,fmode);
+ put_dos_date3(outbuf,smb_vwv4,mtime);
+ SIVAL(outbuf,smb_vwv6,size);
+ SSVAL(outbuf,smb_vwv8,rmode);
+ SSVAL(outbuf,smb_vwv11,smb_action);
+
+ chain_fnum = fnum;
+
+ if (smb_com2 != 0xFF)
+ outsize += chain_reply(smb_com2,inbuf,inbuf+smb_off2+4,
+ outbuf,outbuf+outsize,
+ length,bufsize);
+
+ chain_fnum = -1;
+
+ DEBUG(4,("Opened pipe %s with handle %d, saved name %s.\n",
+ fname, fnum, Files[fnum].name));
+
+ return(outsize);
+}
+
+
+/****************************************************************************
+ api_LsarpcSNPHS
+
+ SetNamedPipeHandleState on \PIPE\lsarpc. We can't really do much here,
+ so just blithely return True. This is really only for NT domain stuff,
+ we we're only handling that - don't assume Samba now does complete
+ named pipe handling.
+****************************************************************************/
+BOOL api_LsarpcSNPHS(int cnum,int uid, char *param,char *data,
+ int mdrcnt,int mprcnt,
+ char **rdata,char **rparam,
+ int *rdata_len,int *rparam_len)
+{
+ uint16 id;
+
+ id = param[0] + (param[1] << 8);
+ DEBUG(4,("lsarpc SetNamedPipeHandleState to code %x\n",id));
+ return(True);
+}
+
+
+/****************************************************************************
+ api_LsarpcTNP
+
+ TransactNamedPipe on \PIPE\lsarpc.
+****************************************************************************/
+static void LsarpcTNP1(char *data,char **rdata, int *rdata_len)
+{
+ uint32 dword1, dword2;
+ char pname[] = "\\PIPE\\lsass";
+
+ /* All kinds of mysterious numbers here */
+ *rdata_len = 68;
+ *rdata = REALLOC(*rdata,*rdata_len);
+
+ dword1 = IVAL(data,0xC);
+ dword2 = IVAL(data,0x10);
+
+ SIVAL(*rdata,0,0xc0005);
+ SIVAL(*rdata,4,0x10);
+ SIVAL(*rdata,8,0x44);
+ SIVAL(*rdata,0xC,dword1);
+
+ SIVAL(*rdata,0x10,dword2);
+ SIVAL(*rdata,0x14,0x15);
+ SSVAL(*rdata,0x18,sizeof(pname));
+ strcpy(*rdata + 0x1a,pname);
+ SIVAL(*rdata,0x28,1);
+ memcpy(*rdata + 0x30, data + 0x34, 0x14);
+}
+
+static void LsarpcTNP2(char *data,char **rdata, int *rdata_len)
+{
+ uint32 dword1;
+
+ /* All kinds of mysterious numbers here */
+ *rdata_len = 48;
+ *rdata = REALLOC(*rdata,*rdata_len);
+
+ dword1 = IVAL(data,0xC);
+
+ SIVAL(*rdata,0,0x03020005);
+ SIVAL(*rdata,4,0x10);
+ SIVAL(*rdata,8,0x30);
+ SIVAL(*rdata,0xC,dword1);
+ SIVAL(*rdata,0x10,0x18);
+ SIVAL(*rdata,0x1c,0x44332211);
+ SIVAL(*rdata,0x20,0x88776655);
+ SIVAL(*rdata,0x24,0xCCBBAA99);
+ SIVAL(*rdata,0x28,0x11FFEEDD);
+}
+
+static void LsarpcTNP3(char *data,char **rdata, int *rdata_len)
+{
+ uint32 dword1;
+ uint16 word1;
+ char * workgroup = lp_workgroup();
+ int wglen = strlen(workgroup);
+ int i;
+
+ /* All kinds of mysterious numbers here */
+ *rdata_len = 90 + 2 * wglen;
+ *rdata = REALLOC(*rdata,*rdata_len);
+
+ dword1 = IVAL(data,0xC);
+ word1 = SVAL(data,0x2C);
+
+ SIVAL(*rdata,0,0x03020005);
+ SIVAL(*rdata,4,0x10);
+ SIVAL(*rdata,8,0x60);
+ SIVAL(*rdata,0xC,dword1);
+ SIVAL(*rdata,0x10,0x48);
+ SSVAL(*rdata,0x18,0x5988); /* This changes */
+ SSVAL(*rdata,0x1A,0x15);
+ SSVAL(*rdata,0x1C,word1);
+ SSVAL(*rdata,0x20,6);
+ SSVAL(*rdata,0x22,8);
+ SSVAL(*rdata,0x24,0x8E8); /* So does this */
+ SSVAL(*rdata,0x26,0x15);
+ SSVAL(*rdata,0x28,0x4D48); /* And this */
+ SSVAL(*rdata,0x2A,0x15);
+ SIVAL(*rdata,0x2C,4);
+ SIVAL(*rdata,0x34,wglen);
+ for ( i = 0 ; i < wglen ; i++ )
+ (*rdata)[0x38 + i * 2] = workgroup[i];
+
+ /* Now fill in the rest */
+ i = 0x38 + wglen * 2;
+ SSVAL(*rdata,i,0x648);
+ SIVAL(*rdata,i+2,4);
+ SIVAL(*rdata,i+6,0x401);
+ SSVAL(*rdata,i+0xC,0x500);
+ SIVAL(*rdata,i+0xE,0x15);
+ SIVAL(*rdata,i+0x12,0x2372FE1);
+ SIVAL(*rdata,i+0x16,0x7E831BEF);
+ SIVAL(*rdata,i+0x1A,0x4B454B2);
+}
+
+static void LsarpcTNP4(char *data,char **rdata, int *rdata_len)
+{
+ uint32 dword1;
+
+ /* All kinds of mysterious numbers here */
+ *rdata_len = 48;
+ *rdata = REALLOC(*rdata,*rdata_len);
+
+ dword1 = IVAL(data,0xC);
+
+ SIVAL(*rdata,0,0x03020005);
+ SIVAL(*rdata,4,0x10);
+ SIVAL(*rdata,8,0x30);
+ SIVAL(*rdata,0xC,dword1);
+ SIVAL(*rdata,0x10,0x18);
+}
+
+
+BOOL api_LsarpcTNP(int cnum,int uid, char *param,char *data,
+ int mdrcnt,int mprcnt,
+ char **rdata,char **rparam,
+ int *rdata_len,int *rparam_len)
+{
+ uint32 id,id2;
+
+ id = IVAL(data,0);
+
+ DEBUG(4,("lsarpc TransactNamedPipe id %lx\n",id));
+ switch (id)
+ {
+ case 0xb0005:
+ LsarpcTNP1(data,rdata,rdata_len);
+ break;
+
+ case 0x03000005:
+ id2 = IVAL(data,8);
+ DEBUG(4,("\t- Suboperation %lx\n",id2));
+ switch (id2 & 0xF)
+ {
+ case 8:
+ LsarpcTNP2(data,rdata,rdata_len);
+ break;
+
+ case 0xC:
+ LsarpcTNP4(data,rdata,rdata_len);
+ break;
+
+ case 0xE:
+ LsarpcTNP3(data,rdata,rdata_len);
+ break;
+ }
+ break;
+ }
+ return(True);
+}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index d463b305c9..a97c8c9c9c 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -294,6 +294,7 @@ int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize)
BOOL valid_nt_password = False;
pstring user;
BOOL guest=False;
+ BOOL computer_id=False;
*smb_apasswd = 0;
@@ -349,6 +350,15 @@ int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize)
DEBUG(3,("sesssetupX:name=[%s]\n",user));
+ /* If name ends in $ then I think it's asking about whether a */
+ /* computer with that name (minus the $) has access. For now */
+ /* say yes to everything ending in $. */
+ if (user[strlen(user) - 1] == '$') {
+ computer_id = True;
+ user[strlen(user) - 1] = '\0';
+ }
+
+
if (!*user)
strcpy(user,lp_guestaccount(-1));
@@ -380,7 +390,7 @@ int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize)
}
if (!valid_nt_password && !guest && !password_ok(user,smb_apasswd,smb_apasslen,NULL,False))
{
- if (lp_security() >= SEC_USER) {
+ if (!computer_id && lp_security() >= SEC_USER) {
#if (GUEST_SESSSETUP == 0)
return(ERROR(ERRSRV,ERRbadpw));
#endif
@@ -444,7 +454,7 @@ int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize)
CVAL(outbuf,smb_vwv0) = smb_com2;
SSVAL(outbuf,smb_vwv1,(chain_size+outsize)-4);
- if (guest)
+ if (guest && !computer_id)
SSVAL(outbuf,smb_vwv2,1);
/* register the name and uid as being validated, so further connections
@@ -980,6 +990,10 @@ int reply_open_and_X(char *inbuf,char *outbuf,int length,int bufsize)
struct stat sbuf;
int smb_action = 0;
+ /* If it's an IPC, pass off the pipe handler. */
+ if (IS_IPC(cnum))
+ return reply_open_pipe_and_X(inbuf,outbuf,length,bufsize);
+
/* XXXX we need to handle passed times, sattr and flags */
strcpy(fname,smb_buf(inbuf));
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 334edf77d0..170062a531 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1584,7 +1584,7 @@ static int sig_cld()
}
depth++;
- BlockSignals(True);
+ BlockSignals(True,SIGCLD);
DEBUG(5,("got SIGCLD\n"));
#ifdef USE_WAITPID
@@ -1610,7 +1610,7 @@ static int sig_cld()
while (wait3(WAIT3_CAST1 NULL, WNOHANG, WAIT3_CAST2 NULL) > 0);
#endif
depth--;
- BlockSignals(False);
+ BlockSignals(False,SIGCLD);
return 0;
}
#endif
@@ -1791,13 +1791,13 @@ this prevents zombie child processes
****************************************************************************/
static int sig_hup()
{
- BlockSignals(True);
+ BlockSignals(True,SIGHUP);
DEBUG(0,("Got SIGHUP\n"));
reload_services(False);
#ifndef DONT_REINSTALL_SIG
signal(SIGHUP,SIGNAL_CAST sig_hup);
#endif
- BlockSignals(False);
+ BlockSignals(False,SIGHUP);
return(0);
}
@@ -3011,7 +3011,7 @@ struct smb_message_struct
{SMBunlink,"SMBunlink",reply_unlink,AS_USER | NEED_WRITE},
{SMBread,"SMBread",reply_read,AS_USER},
{SMBwrite,"SMBwrite",reply_write,AS_USER},
- {SMBclose,"SMBclose",reply_close,AS_USER},
+ {SMBclose,"SMBclose",reply_close,AS_USER | CAN_IPC},
{SMBmkdir,"SMBmkdir",reply_mkdir,AS_USER | NEED_WRITE},
{SMBrmdir,"SMBrmdir",reply_rmdir,AS_USER | NEED_WRITE},
{SMBdskattr,"SMBdskattr",reply_dskattr,AS_USER},
@@ -3054,7 +3054,7 @@ struct smb_message_struct
{SMBcopy,"SMBcopy",reply_copy,AS_USER | NEED_WRITE},
{SMBmove,"SMBmove",NULL,AS_USER | NEED_WRITE},
- {SMBopenX,"SMBopenX",reply_open_and_X,AS_USER},
+ {SMBopenX,"SMBopenX",reply_open_and_X,AS_USER | CAN_IPC},
{SMBreadX,"SMBreadX",reply_read_and_X,AS_USER},
{SMBwriteX,"SMBwriteX",reply_write_and_X,AS_USER},
{SMBlockingX,"SMBlockingX",reply_lockingX,AS_USER},
@@ -3456,7 +3456,7 @@ static void process(void)
/* clean the share modes every 5 minutes */
if (!(counter%SHARE_MODES_CLEAN))
- clean_share_files();
+ clean_share_modes();
/* automatic timeout if all connections are closed */
if (num_connections_open==0 && counter >= IDLE_CLOSED_TIMEOUT) {
@@ -3744,6 +3744,11 @@ static void usage(char *pname)
if (!open_sockets(is_daemon,port))
exit(1);
+#ifdef FAST_SHARE_MODES
+ if (!start_share_mode_mgmt())
+ exit(1);
+#endif
+
/* possibly reload the services file. */
reload_services(True);
@@ -3758,6 +3763,10 @@ static void usage(char *pname)
process();
close_sockets();
+#ifdef FAST_SHARE_MODES
+ stop_share_mode_mgmt();
+#endif
+
exit_server("normal exit");
return(0);
}
diff --git a/source3/utils/status.c b/source3/utils/status.c
index 3d52056489..c9fda5d359 100644
--- a/source3/utils/status.c
+++ b/source3/utils/status.c
@@ -17,6 +17,11 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ Revision History:
+
+ 12 aug 96: Erik.Devriendt@te6.siemens.be
+ added support for shared memory implementation of share mode locking
*/
/*
@@ -43,15 +48,24 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */
{
FILE *f;
pstring fname;
- int uid, c, n;
+ int uid, c;
static pstring servicesf = CONFIGFILE;
extern char *optarg;
int verbose = 0;
- void *dir;
- char *s;
BOOL firstopen=True;
BOOL processes_only=False;
int last_pid=0;
+#ifdef FAST_SHARE_MODES
+ pstring shmem_file_name;
+ share_mode_record *scanner_p;
+ share_mode_record *prev_p;
+ int bytes_free, bytes_used, bytes_overhead, bytes_total;
+#else
+ int n;
+ void *dir;
+ char *s;
+#endif
+
TimeInit();
setup_logging(argv[0],True);
@@ -151,42 +165,99 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */
printf("\n");
- dir = opendir(lp_lockdir());
- if (!dir) return(0);
- while ((s=readdirname(dir))) {
- char buf[16];
- int pid,mode;
- time_t t;
- int fd;
- pstring lname;
- int dev,inode;
-
- if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue;
-
- strcpy(lname,lp_lockdir());
- trim_string(lname,NULL,"/");
- strcat(lname,"/");
- strcat(lname,s);
-
- fd = open(lname,O_RDONLY,0);
- if (fd < 0) continue;
- if (read(fd,buf,16) != 16) continue;
- n = read(fd,fname,sizeof(fname));
- fname[MAX(n,0)]=0;
- close(fd);
-
- t = IVAL(buf,0);
- mode = IVAL(buf,4);
- pid = IVAL(buf,8);
-
- if ( !Ucrit_checkPid(pid) ) /* added by OH */
- continue;
-
- if (IVAL(buf,12) != LOCKING_VERSION || !process_exists(pid)) {
- if (unlink(lname)==0)
- printf("Deleted stale share file %s\n",s);
- continue;
- }
+#ifdef FAST_SHARE_MODES
+ /*******************************************************************
+ initialize the shared memory for share_mode management
+ ******************************************************************/
+
+
+ strcpy(shmem_file_name,lp_lockdir());
+ trim_string(shmem_file_name,"","/");
+ if (!*shmem_file_name) exit(-1);
+ strcat(shmem_file_name, "/SHARE_MEM_FILE");
+ if(!shm_open(shmem_file_name, SHMEM_SIZE)) exit(-1);
+
+ if(!shm_lock())
+ {
+ shm_close();
+ exit (-1);
+ }
+
+ scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off());
+ prev_p = scanner_p;
+ while(scanner_p)
+ {
+ int pid,mode;
+ time_t t;
+
+ pid = scanner_p->pid;
+
+ if ( !Ucrit_checkPid(pid) )
+ {
+ prev_p = scanner_p ;
+ scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset);
+ continue;
+ }
+
+ if( (scanner_p->locking_version != LOCKING_VERSION) || !process_exists(pid))
+ {
+ DEBUG(2,("Deleting stale share mode record"));
+ if(prev_p == scanner_p)
+ {
+ shm_set_userdef_off(scanner_p->next_offset);
+ shm_free(shm_addr2offset(scanner_p));
+ scanner_p = (share_mode_record *)shm_offset2addr(shm_get_userdef_off());
+ prev_p = scanner_p;
+ }
+ else
+ {
+ prev_p->next_offset = scanner_p->next_offset;
+ shm_free(shm_addr2offset(scanner_p));
+ scanner_p = (share_mode_record *)shm_offset2addr(prev_p->next_offset);
+ }
+ continue;
+ }
+ t = scanner_p->time;
+ mode = scanner_p->share_mode;
+ strcpy(fname, scanner_p->file_name);
+#else
+ dir = opendir(lp_lockdir());
+ if (!dir) return(0);
+ while ((s=readdirname(dir))) {
+ char buf[16];
+ int pid,mode;
+ time_t t;
+ int fd;
+ pstring lname;
+ int dev,inode;
+
+ if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue;
+
+ strcpy(lname,lp_lockdir());
+ trim_string(lname,NULL,"/");
+ strcat(lname,"/");
+ strcat(lname,s);
+
+ fd = open(lname,O_RDONLY,0);
+ if (fd < 0) continue;
+ if (read(fd,buf,16) != 16) continue;
+ n = read(fd,fname,sizeof(fname));
+ fname[MAX(n,0)]=0;
+ close(fd);
+
+ t = IVAL(buf,0);
+ mode = IVAL(buf,4);
+ pid = IVAL(buf,8);
+
+ if ( !Ucrit_checkPid(pid) ) /* added by OH */
+ continue;
+
+ if (IVAL(buf,12) != LOCKING_VERSION || !process_exists(pid)) {
+ if (unlink(lname)==0)
+ printf("Deleted stale share file %s\n",s);
+ continue;
+ }
+#endif
fname[sizeof(fname)-1] = 0;
@@ -214,11 +285,37 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */
case 2: printf("RDWR "); break;
}
printf(" %s %s",fname,asctime(LocalTime(&t)));
- }
+
+#ifdef FAST_SHARE_MODES
+ prev_p = scanner_p ;
+ scanner_p = (share_mode_record *)shm_offset2addr(scanner_p->next_offset);
+ } /* end while */
+
+ shm_get_usage(&bytes_free, &bytes_used, &bytes_overhead);
+ bytes_total = bytes_free + bytes_used + bytes_overhead;
+ shm_unlock();
+
+ /*******************************************************************
+ deinitialize the shared memory for share_mode management
+ ******************************************************************/
+ shm_close();
+
+#else
+ } /* end while */
closedir(dir);
+#endif
if (firstopen)
printf("No locked files\n");
+#ifdef FAST_SHARE_MODES
+ printf("\nShare mode memory usage (bytes):\n");
+ printf(" %d(%d%%) free + %d(%d%%) used + %d(%d%%) overhead = %d(100%%) total\n",
+ bytes_free, (bytes_free * 100)/bytes_total,
+ bytes_used, (bytes_used * 100)/bytes_total,
+ bytes_overhead, (bytes_overhead * 100)/bytes_total,
+ bytes_total);
+
+#endif
return (0);
}