summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-10-25 14:54:41 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:05:11 -0500
commitbac6524af1ab318270e4ceafeaabbe870a3b7776 (patch)
tree8e2608d1ee835feb951393695b1d5df377ee2370
parent90b1ca259706e7ae31c0ce7384a9e448a771f1b7 (diff)
downloadsamba-bac6524af1ab318270e4ceafeaabbe870a3b7776.tar.gz
samba-bac6524af1ab318270e4ceafeaabbe870a3b7776.tar.bz2
samba-bac6524af1ab318270e4ceafeaabbe870a3b7776.zip
r11295: new service hashing code has assumign that the service
name stored in the array was normalized. This was causing records to not be deleted on a reload. As a result, I was getting the wrong path for various services. Seems to be ok after this change. Also converted canonicalize_servicename() to just use strupper_m() rather than doing the conversion itself. Jeremy, i think this should be ok but please check. also cleaned up some things in the hash service code and added debug messages for sanity purposes. (This used to be commit e0bf0581f0aaf1505f653f2101eed61352d03da8)
-rw-r--r--source3/param/loadparm.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index f084d52c26..6ad1ace755 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -2343,15 +2343,20 @@ static void free_service(service *pservice)
static void free_service_byindex(int idx)
{
- if (!LP_SNUM_OK(idx)) {
+ if ( !LP_SNUM_OK(idx) )
return;
- }
ServicePtrs[idx]->valid = False;
invalid_services[num_invalid_services++] = idx;
+
+ /* we have to cleanup the hash record */
+
if (ServicePtrs[idx]->szService) {
- tdb_delete_bystring(ServiceHash, ServicePtrs[idx]->szService);
+ char *canon_name = canonicalize_servicename( ServicePtrs[idx]->szService );
+
+ tdb_delete_bystring(ServiceHash, canon_name );
}
+
free_service(ServicePtrs[idx]);
}
@@ -2452,6 +2457,15 @@ static char *canonicalize_servicename(const char *src)
static fstring canon; /* is fstring large enough? */
int dst_idx = 0;
+ if ( !src ) {
+ DEBUG(0,("canonicalize_servicename: NULL source name!\n"));
+ return NULL;
+ }
+
+ fstrcpy( canon, src );
+ strupper_m( canon );
+
+#if 0
for (; *src != '\0'; src += next_mb_char_size(src)) {
if (isspace(*src)) {
continue;
@@ -2462,6 +2476,8 @@ static char *canonicalize_servicename(const char *src)
canon[dst_idx++] = toupper(*src);
}
canon[dst_idx] = '\0';
+#endif
+
return canon;
}
@@ -2471,18 +2487,26 @@ static char *canonicalize_servicename(const char *src)
static BOOL hash_a_service(const char *name, int idx)
{
- if (ServiceHash == NULL) {
+ char *canon_name;
+
+ if ( !ServiceHash ) {
DEBUG(10,("hash_a_service: creating tdb servicehash\n"));
ServiceHash = tdb_open("servicehash", 1031, TDB_INTERNAL,
- (O_RDWR|O_CREAT), 0644);
- if (ServiceHash == NULL) {
+ (O_RDWR|O_CREAT), 0600);
+ if ( !ServiceHash ) {
DEBUG(0,("hash_a_service: open tdb servicehash failed!\n"));
return False;
}
}
+
DEBUG(10,("hash_a_service: hashing index %d for service name %s\n",
- idx, name));
- tdb_store_int32(ServiceHash, canonicalize_servicename(name), idx);
+ idx, name));
+
+ if ( !(canon_name = canonicalize_servicename( name )) )
+ return False;
+
+ tdb_store_int32(ServiceHash, canon_name, idx);
+
return True;
}
@@ -2719,19 +2743,23 @@ Find a service by name. Otherwise works like get_service.
static int getservicebyname(const char *pszServiceName, service * pserviceDest)
{
int iService = -1;
+ char *canon_name;
if (ServiceHash != NULL) {
- iService = tdb_fetch_int32(ServiceHash,
- canonicalize_servicename(pszServiceName));
+ if ( !(canon_name = canonicalize_servicename( pszServiceName )) )
+ return -1;
+
+ iService = tdb_fetch_int32(ServiceHash, canon_name );
+
if (LP_SNUM_OK(iService)) {
if (pserviceDest != NULL) {
- copy_service(pserviceDest,
- ServicePtrs[iService], NULL);
+ copy_service(pserviceDest, ServicePtrs[iService], NULL);
}
} else {
iService = -1;
}
}
+
return (iService);
}