diff options
author | Andrew Tridgell <tridge@samba.org> | 1997-10-29 01:59:54 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1997-10-29 01:59:54 +0000 |
commit | 4fd96fddd2b13f60c4eb13263bac2a62a2795dcc (patch) | |
tree | 93c269b25da65f647dcca036b8d3682021142d68 /source3/locking/shmem.c | |
parent | b925b3d20c8e85c7b65a0ad599248443ae12905c (diff) | |
download | samba-4fd96fddd2b13f60c4eb13263bac2a62a2795dcc.tar.gz samba-4fd96fddd2b13f60c4eb13263bac2a62a2795dcc.tar.xz samba-4fd96fddd2b13f60c4eb13263bac2a62a2795dcc.zip |
clean up the hash entry code a bit. Got rid of lp_shmem_hash_size()
and made it private to the 2 shmem implementations. Added new
shmops->hash_size() function.
Added code to handle the IPC system limits by looping decreasing the
size of the resources (semaphores and shared memory) that we request
until we get under the system limits, which can be quite low on some
systems!
Added checks that the creator of the IPC objects is root. Otherwise we
would be open to a security hole where someone pre-creates the shared
memory segment and attaches.
(This used to be commit 6b6f624b63137d4750200e8cb4961b1402513632)
Diffstat (limited to 'source3/locking/shmem.c')
-rw-r--r-- | source3/locking/shmem.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c index 72d7c07751..909e8dd435 100644 --- a/source3/locking/shmem.c +++ b/source3/locking/shmem.c @@ -41,6 +41,9 @@ extern int DEBUGLEVEL; #define SHM_FILE_MODE 0644 #endif +#define SHMEM_HASH_SIZE 113 + + /* WARNING : offsets are used because mmap() does not guarantee that all processes have the shared memory mapped to the same address */ @@ -653,12 +656,6 @@ static BOOL smb_shm_lock_hash_entry( unsigned int entry) return False; } - if(entry >= lp_shmem_hash_size()) - { - DEBUG(0,("ERROR smb_shm_lock_hash_entry : hash entry size too big (%d)\n", entry)); - return False; - } - /* Do an exclusive wait lock on the 4 byte region mapping into this entry */ if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(int), F_WRLCK) == False) { @@ -683,12 +680,6 @@ static BOOL smb_shm_unlock_hash_entry( unsigned int entry ) return False; } - if(entry >= lp_shmem_hash_size()) - { - DEBUG(0,("ERROR smb_shm_unlock_hash_entry : hash entry size too big (%d)\n", entry)); - return False; - } - /* Do a wait lock on the 4 byte region mapping into this entry */ if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(int), F_UNLCK) == False) { @@ -720,6 +711,13 @@ static BOOL smb_shm_get_usage(int *bytes_free, return True; } +/******************************************************************* +hash a number into a hash_entry + ******************************************************************/ +static unsigned smb_shm_hash_size(void) +{ + return SHMEM_HASH_SIZE; +} static struct shmem_ops shmops = { smb_shm_close, @@ -731,18 +729,30 @@ static struct shmem_ops shmops = { smb_shm_lock_hash_entry, smb_shm_unlock_hash_entry, smb_shm_get_usage, + smb_shm_hash_size, }; /******************************************************************* open the shared memory ******************************************************************/ -struct shmem_ops *smb_shm_open(char *file_name, int size, int ronly) +struct shmem_ops *smb_shm_open(int ronly) { - int filesize; - BOOL created_new = False; - BOOL other_processes = True; - - read_only = ronly; + pstring file_name; + int filesize; + BOOL created_new = False; + BOOL other_processes = True; + int size = lp_shmem_size(); + + read_only = ronly; + + pstrcpy(file_name,lp_lockdir()); + if (!directory_exist(file_name,NULL)) { + if (read_only) return NULL; + mkdir(file_name,0755); + } + trim_string(file_name,"","/"); + if (!*file_name) return(False); + strcat(file_name, "/SHARE_MEM_FILE"); DEBUG(5,("smb_shm_open : using shmem file %s to be of size %d\n",file_name,size)); @@ -840,7 +850,7 @@ struct shmem_ops *smb_shm_open(char *file_name, int size, int ronly) { smb_shm_initialize(size); /* Create the hash buckets for the share file entries. */ - smb_shm_create_hash_table( lp_shmem_hash_size() ); + smb_shm_create_hash_table(SHMEM_HASH_SIZE); } else if (!smb_shm_validate_header(size) ) { |