[dovecot-cvs] dovecot/src/auth passdb-ldap.c,1.45,1.46

cras at dovecot.org cras at dovecot.org
Thu Aug 10 22:44:22 EEST 2006


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv18888

Modified Files:
	passdb-ldap.c 
Log Message:
If password query returns userdb_ prefixed fields (ie. for userdb prefetch)
but not userdb_uid or userdb_gid, add them based on the global uid/gid
settings.



Index: passdb-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-ldap.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- passdb-ldap.c	1 Jul 2006 18:40:34 -0000	1.45
+++ passdb-ldap.c	10 Aug 2006 19:44:19 -0000	1.46
@@ -44,6 +44,8 @@
 	char *attr, **vals;
 	unsigned int i;
 	string_t *debug = NULL;
+	bool userdb_fields = FALSE;
+	bool add_userdb_uid = FALSE, add_userdb_gid = FALSE;
 
 	attr = ldap_first_attribute(conn->ld, entry, &ber);
 	while (attr != NULL) {
@@ -60,6 +62,19 @@
 				    name != NULL ? name : "?unknown?");
 		}
 
+		if (strncmp(name, "userdb_", 7) == 0) {
+			/* in case we're trying to use prefetch userdb,
+			   see if we need to add global uid/gid */
+			if (!userdb_fields) {
+				add_userdb_uid = add_userdb_gid = TRUE;
+				userdb_fields = TRUE;
+			}
+			if (strcmp(name, "userdb_uid") == 0)
+				add_userdb_uid = FALSE;
+			else if (strcmp(name, "userdb_gid") == 0)
+				add_userdb_gid = FALSE;
+		}
+
 		if (name != NULL && vals != NULL && *name != '\0') {
 			for (i = 0; vals[i] != NULL; i++) {
 				if (debug != NULL) {
@@ -85,6 +100,15 @@
 		attr = ldap_next_attribute(conn->ld, entry, ber);
 	}
 
+	if (add_userdb_uid && conn->set.uid != (uid_t)-1) {
+		auth_request_set_field(auth_request, "userdb_uid",
+				       dec2str(conn->set.uid), NULL);
+	}
+	if (add_userdb_gid && conn->set.gid != (gid_t)-1) {
+		auth_request_set_field(auth_request, "userdb_gid",
+				       dec2str(conn->set.gid), NULL);
+	}
+
 	if (debug != NULL) {
 		auth_request_log_debug(auth_request, "ldap",
 				       "%s", str_c(debug));



More information about the dovecot-cvs mailing list