svn commit: samba r18313 - in branches/SAMBA_3_0/source: lib passdb utils

vlendec at samba.org vlendec at samba.org
Sat Sep 9 22:27:07 GMT 2006


Author: vlendec
Date: 2006-09-09 22:27:06 +0000 (Sat, 09 Sep 2006)
New Revision: 18313

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

Log:
Nobody said "no" (yet.... gd?), so commit it:

Remove the account_policy_migrated() thingy, and make cache_account_policy_set
use gencache. Account policies are now handled like groups and users are with
respect to "passdb backend".

Volker

Modified:
   branches/SAMBA_3_0/source/lib/account_pol.c
   branches/SAMBA_3_0/source/passdb/pdb_ldap.c
   branches/SAMBA_3_0/source/utils/pdbedit.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/account_pol.c
===================================================================
--- branches/SAMBA_3_0/source/lib/account_pol.c	2006-09-09 21:40:47 UTC (rev 18312)
+++ branches/SAMBA_3_0/source/lib/account_pol.c	2006-09-09 22:27:06 UTC (rev 18313)
@@ -28,7 +28,6 @@
  * ldap directly) - gd */
 
 #define DATABASE_VERSION 	3
-#define AP_LASTSET 		"LAST_CACHE_UPDATE"
 #define AP_TTL			60
 
 
@@ -169,50 +168,6 @@
 }
 
 /*****************************************************************************
-Update LAST-Set counter inside the cache
-*****************************************************************************/
-
-static BOOL account_policy_cache_timestamp(uint32 *value, BOOL update, 
-					   const char *ap_name)
-{
-	pstring key;
-	uint32 val = 0;
-	time_t now;
-
-	if (ap_name == NULL)
-		return False;
-		
-	slprintf(key, sizeof(key)-1, "%s/%s", ap_name, AP_LASTSET);
-
-	if (!init_account_policy()) {
-		return False;
-	}
-
-	if (!tdb_fetch_uint32(tdb, key, &val) && !update) {
-		DEBUG(10,("failed to get last set timestamp of cache\n"));
-		return False;
-	}
-
-	*value = val;
-
-	DEBUG(10, ("account policy cache lastset was: %s\n", http_timestring(val)));
-
-	if (update) {
-
-		now = time(NULL);
-
-		if (!tdb_store_uint32(tdb, key, (uint32)now)) {
-			DEBUG(1, ("tdb_store_uint32 failed for %s\n", key));
-			return False;
-		}
-		DEBUG(10, ("account policy cache lastset now: %s\n", http_timestring(now)));
-		*value = now;
-	}
-
-	return True;
-}
-
-/*****************************************************************************
 Get default value for account policy
 *****************************************************************************/
 
@@ -269,11 +224,6 @@
 			DEBUG(0,("Failed to open account policy database\n"));
 			return False;
 		}
-		/* creation was successful */
-	       	/* add AP_MIGRATED_TO_PASSDB speacial key */
-		/* so that you do not need to migrate policies */
-		/* on brand new servers as it does not make sense */
-		account_policy_migrated(True);
 	}
 
 	/* handle a Samba upgrade */
@@ -319,7 +269,7 @@
 
 BOOL account_policy_get(int field, uint32 *value)
 {
-	fstring name;
+	const char *name;
 	uint32 regval;
 
 	if (!init_account_policy()) {
@@ -330,8 +280,8 @@
 		*value = 0;
 	}
 
-	fstrcpy(name, decode_account_policy_name(field));
-	if (!*name) {
+	name = decode_account_policy_name(field);
+	if (name == NULL) {
 		DEBUG(1, ("account_policy_get: Field %d is not a valid account policy type!  Cannot get, returning 0.\n", field));
 		return False;
 	}
@@ -356,14 +306,14 @@
 
 BOOL account_policy_set(int field, uint32 value)
 {
-	fstring name;
+	const char *name;
 
 	if (!init_account_policy()) {
 		return False;
 	}
 
-	fstrcpy(name, decode_account_policy_name(field));
-	if (!*name) {
+	name = decode_account_policy_name(field);
+	if (name == NULL) {
 		DEBUG(1, ("Field %d is not a valid account policy type!  Cannot set.\n", field));
 		return False;
 	}
@@ -384,8 +334,10 @@
 
 BOOL cache_account_policy_set(int field, uint32 value)
 {
-	uint32 lastset;
 	const char *policy_name = NULL;
+	char *cache_key = NULL;
+	char *cache_value = NULL;
+	BOOL ret = False;
 
 	policy_name = decode_account_policy_name(field);
 	if (policy_name == NULL) {
@@ -393,95 +345,60 @@
 		return False;
 	}
 
-	DEBUG(10,("cache_account_policy_set: updating account pol cache\n"));
-
-	if (!account_policy_set(field, value)) {
-		return False;
+	if (asprintf(&cache_key, "ACCT_POL/%s", policy_name) < 0) {
+		DEBUG(0, ("asprintf failed\n"));
+		goto done;
 	}
 
-	if (!account_policy_cache_timestamp(&lastset, True, policy_name)) 
-	{
-		DEBUG(10,("cache_account_policy_set: failed to get lastest cache update timestamp\n"));
-		return False;
+	if (asprintf(&cache_value, "%lu\n", (unsigned long)value) < 0) {
+		DEBUG(0, ("asprintf failed\n"));
+		goto done;
 	}
 
-	DEBUG(10,("cache_account_policy_set: cache valid until: %s\n", http_timestring(lastset+AP_TTL)));
+	DEBUG(10,("cache_account_policy_set: updating account pol cache\n"));
 
-	return True;
+	ret = gencache_set(cache_key, cache_value, time(NULL)+AP_TTL);
+
+ done:
+	SAFE_FREE(cache_key);
+	SAFE_FREE(cache_value);
+	return ret;
 }
 
 /*****************************************************************************
-Check whether account policies have been migrated to passdb
+Get an account policy from the cache 
 *****************************************************************************/
 
-BOOL account_policy_migrated(BOOL init)
+BOOL cache_account_policy_get(int field, uint32 *value)
 {
-	pstring key;
-	uint32 val;
-	time_t now;
+	const char *policy_name = NULL;
+	char *cache_key = NULL;
+	char *cache_value = NULL;
+	BOOL ret = False;
 
-	slprintf(key, sizeof(key)-1, "AP_MIGRATED_TO_PASSDB");
-
-	if (!init_account_policy()) {
+	policy_name = decode_account_policy_name(field);
+	if (policy_name == NULL) {
+		DEBUG(0,("cache_account_policy_set: no policy found\n"));
 		return False;
 	}
 
-	if (init) {
-		now = time(NULL);
-
-		if (!tdb_store_uint32(tdb, key, (uint32)now)) {
-			DEBUG(1, ("tdb_store_uint32 failed for %s\n", key));
-			return False;
-		}
-
-		return True;
+	if (asprintf(&cache_key, "ACCT_POL/%s", policy_name) < 0) {
+		DEBUG(0, ("asprintf failed\n"));
+		goto done;
 	}
 
-	if (!tdb_fetch_uint32(tdb, key, &val)) {
-		return False;
+	if (gencache_get(cache_key, &cache_value, NULL)) {
+		uint32 tmp = strtoul(cache_value, NULL, 10);
+		*value = tmp;
+		ret = True;
 	}
 
-	return True;
+ done:
+	SAFE_FREE(cache_key);
+	SAFE_FREE(cache_value);
+	return ret;
 }
 
-/*****************************************************************************
- Remove marker that informs that account policies have been migrated to passdb
-*****************************************************************************/
-
-BOOL remove_account_policy_migrated(void)
-{
-	if (!init_account_policy()) {
-		return False;
-	}
-
-	return tdb_delete_bystring(tdb, "AP_MIGRATED_TO_PASSDB");
-}
-
-
-/*****************************************************************************
-Get an account policy from the cache 
-*****************************************************************************/
-
-BOOL cache_account_policy_get(int field, uint32 *value)
-{
-	uint32 lastset;
-
-	if (!account_policy_cache_timestamp(&lastset, False, 
-					    decode_account_policy_name(field))) 
-	{
-		DEBUG(10,("cache_account_policy_get: failed to get latest cache update timestamp\n"));
-		return False;
-	}
-
-	if ((lastset + AP_TTL) < (uint32)time(NULL) ) {
-		DEBUG(10,("cache_account_policy_get: no valid cache entry (cache expired)\n"));
-		return False;
-	} 
-
-	return account_policy_get(field, value);
-}
-
-
 /****************************************************************************
 ****************************************************************************/
 

Modified: branches/SAMBA_3_0/source/passdb/pdb_ldap.c
===================================================================
--- branches/SAMBA_3_0/source/passdb/pdb_ldap.c	2006-09-09 21:40:47 UTC (rev 18312)
+++ branches/SAMBA_3_0/source/passdb/pdb_ldap.c	2006-09-09 22:27:06 UTC (rev 18313)
@@ -3495,11 +3495,6 @@
 static NTSTATUS ldapsam_set_account_policy(struct pdb_methods *methods,
 					   int policy_index, uint32 value)
 {
-	if (!account_policy_migrated(False)) {
-		return (account_policy_set(policy_index, value)) ?
-			NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
-	}
-
 	return ldapsam_set_account_policy_in_ldap(methods, policy_index,
 						  value);
 }
@@ -3588,11 +3583,6 @@
 {
 	NTSTATUS ntstatus = NT_STATUS_UNSUCCESSFUL;
 
-	if (!account_policy_migrated(False)) {
-		return (account_policy_get(policy_index, value))
-			? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
-	}
-
 	if (cache_account_policy_get(policy_index, value)) {
 		DEBUG(11,("ldapsam_get_account_policy: got valid value from "
 			  "cache\n"));

Modified: branches/SAMBA_3_0/source/utils/pdbedit.c
===================================================================
--- branches/SAMBA_3_0/source/utils/pdbedit.c	2006-09-09 21:40:47 UTC (rev 18312)
+++ branches/SAMBA_3_0/source/utils/pdbedit.c	2006-09-09 22:27:06 UTC (rev 18313)
@@ -176,11 +176,6 @@
 		}
 	}
 
-	if (!remove_account_policy_migrated()) {
-		fprintf(stderr, "Can't remove marker from tdb\n");
-		return -1;
-	}
-
 	return 0;
 }
 
@@ -193,11 +188,6 @@
 {
 	int i;
 
-	if (!account_policy_migrated(True)) {
-		fprintf(stderr, "Unable to set account policy marker in tdb\n");
-		return -1;
-	}
-
 	for ( i=1; decode_account_policy_name(i) != NULL; i++ ) {
 		uint32 policy_value;
 		NTSTATUS status;
@@ -206,7 +196,6 @@
 
 		if ( NT_STATUS_IS_ERR(status) ) {
 			fprintf(stderr, "Unable to get account policy from %s\n", in->name);
-			remove_account_policy_migrated();
 			return -1;
 		}
 
@@ -214,7 +203,6 @@
 
 		if ( NT_STATUS_IS_ERR(status) ) {
 			fprintf(stderr, "Unable to migrate account policy to %s\n", out->name);
-			remove_account_policy_migrated();
 			return -1;
 		}
 	}



More information about the samba-cvs mailing list