svn commit: samba r11295 - branches/SAMBA_3_0/source/param trunk/source/param

jerry at samba.org jerry at samba.org
Tue Oct 25 14:54:42 GMT 2005


Author: jerry
Date: 2005-10-25 14:54:41 +0000 (Tue, 25 Oct 2005)
New Revision: 11295

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11295

Log:
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.




Modified:
   branches/SAMBA_3_0/source/param/loadparm.c
   trunk/source/param/loadparm.c


Changeset:
Modified: branches/SAMBA_3_0/source/param/loadparm.c
===================================================================
--- branches/SAMBA_3_0/source/param/loadparm.c	2005-10-25 13:43:37 UTC (rev 11294)
+++ branches/SAMBA_3_0/source/param/loadparm.c	2005-10-25 14:54:41 UTC (rev 11295)
@@ -2343,15 +2343,20 @@
 
 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 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 @@
 		canon[dst_idx++] = toupper(*src);
 	}
 	canon[dst_idx] = '\0';
+#endif
+
 	return canon;
 }
 
@@ -2471,18 +2487,26 @@
 
 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 @@
 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);
 }
 

Modified: trunk/source/param/loadparm.c
===================================================================
--- trunk/source/param/loadparm.c	2005-10-25 13:43:37 UTC (rev 11294)
+++ trunk/source/param/loadparm.c	2005-10-25 14:54:41 UTC (rev 11295)
@@ -2343,15 +2343,20 @@
 
 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 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 @@
 		canon[dst_idx++] = toupper(*src);
 	}
 	canon[dst_idx] = '\0';
+#endif
+
 	return canon;
 }
 
@@ -2471,18 +2487,26 @@
 
 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 @@
 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);
 }
 



More information about the samba-cvs mailing list