Re: Using different attribut names in LDAP ?

Marius Tomaschewski <[email protected]> Fri, 5 Aug 2005 03:59:03 +0200
Newsgroups gmane.linux.suse.proxy-suite
Organization MaT@Home
Message-ID <[email protected]>
--DBIVS5p969aUjpLe
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

On Wed, Aug 03, 2005 at 04:42:23PM +0200, [email protected] wrote:
> Is there an easy way to rename the attributes that are asked via LDAP,
> or do we have to change them in the source code ?
> 
> If the source code change is the only way, would changing them in
> ftp-ldap.c suffice or not ?

Yes, it is sufficient.

See attached patch - I've extracted the attribute values to the
ftp-ldap.h file, so it should be easier to find and replace them.

Please verify the patch - I've just written it without any test!

Bye,
 Marius.
--
 ° --- Marius Tomaschewski <[email protected]>, Germany --- °
   The number of UNIX installations has grown to 10, with
   more expected.
   - The Unix Programmer's Manual, 2nd Edition, June 1972

--DBIVS5p969aUjpLe
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="ftp-ldap-attrs.diff"

Index: ftp-ldap.c
===================================================================
RCS file: /data/cvs/CVS-PSUITE/PROXY-SUITE/ftp-proxy/ftp-ldap.c,v
retrieving revision 1.7.2.3
diff -u -p -r1.7.2.3 ftp-ldap.c
--- ftp-ldap.c	10 Mar 2004 16:07:13 -0000	1.7.2.3
+++ ftp-ldap.c	5 Aug 2005 01:52:24 -0000
@@ -601,7 +601,7 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 	/*
 	** Evaluate the destination FTP server address.
 	*/
-	p = ldap_attrib(ld, e, "DestinationAddress", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_DESTINATION_ADDRESS, NULL);
 	if(NULL != p && ctx->magic_addr == INADDR_ANY) {
 		ctx->srv_addr = socket_str2addr(p, INADDR_ANY);
 		if(INADDR_ANY == ctx->srv_addr) {
@@ -619,7 +619,7 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 	/*
 	** Evaluate the destination FTP server port
 	*/
-	p = ldap_attrib(ld, e, "DestinationPort", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_DESTINATION_PORT, NULL);
 	if(NULL != p && ctx->magic_port == INPORT_ANY) {
 		ctx->srv_port = socket_str2port(p, INPORT_ANY);
 		if(INPORT_ANY == ctx->srv_port) {
@@ -637,7 +637,7 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 	/*
 	** Evaluate the destination transfer mode
 	*/
-	p = ldap_attrib(ld, e, "DestinationTransferMode", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_DESTINATION_TRANSFER_MODE, NULL);
 	if(NULL != p) {
 		if(strcasecmp(p, "active") == 0)
 			ctx->srv_mode = MOD_ACT_FTP;
@@ -659,8 +659,8 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 	/*
 	** Evaluate the port ranges
 	*/
-	p = ldap_attrib(ld, e, "DestinationMinPort", NULL);
-	q = ldap_attrib(ld, e, "DestinationMaxPort", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_DESTINATION_MIN_PORT, NULL);
+	q = ldap_attrib(ld, e, FTP_LDAP_DESTINATION_MAX_PORT, NULL);
 	if(NULL != p && NULL != q) {
 		l = socket_str2port(p, INPORT_ANY);
 		u = socket_str2port(q, INPORT_ANY);
@@ -674,8 +674,8 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 #endif
 	}
 
-	p = ldap_attrib(ld, e, "ActiveMinDataPort", NULL);
-	q = ldap_attrib(ld, e, "ActiveMaxDataPort", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_ACTIVE_MIN_DATA_PORT, NULL);
+	q = ldap_attrib(ld, e, FTP_LDAP_ACTIVE_MAX_DATA_PORT, NULL);
 	if(NULL != p && NULL != q) {
 		l = socket_str2port(p, INPORT_ANY);
 		u = socket_str2port(q, INPORT_ANY);
@@ -689,8 +689,8 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 #endif
 	}
 
-	p = ldap_attrib(ld, e, "PassiveMinDataPort", NULL);
-	q = ldap_attrib(ld, e, "PassiveMaxDataPort", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_PASSIVE_MIN_DATA_PORT, NULL);
+	q = ldap_attrib(ld, e, FTP_LDAP_PASSIVE_MAX_DATA_PORT, NULL);
 	if(NULL != p && NULL != q) {
 		l = socket_str2port(p, INPORT_ANY);
 		u = socket_str2port(q, INPORT_ANY);
@@ -707,7 +707,7 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 	/*
 	** Setup other configuration options
 	*/
-	p = ldap_attrib(ld, e, "SameAddress", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_SAME_ADDRESS, NULL);
 	if(NULL != p) {
 		if (strcasecmp(p, "y") == 0)
 			ctx->same_adr = 1;
@@ -726,7 +726,7 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 		         ctx->same_adr ? "yes" : "no");
 #endif
 	}
-	p = ldap_attrib(ld, e, "TimeOut", "900");
+	p = ldap_attrib(ld, e, FTP_LDAP_TIME_OUT, "900");
 	if(NULL != p) {
 		if (*p >= '0' && *p <= '9')
 			ctx->timeout = atoi(p);
@@ -741,7 +741,7 @@ static int ldap_fetch(LDAP *ld, CONTEXT 
 	/*
 	** Adjust the allow/deny flags for the commands
 	*/
-	p = ldap_attrib(ld, e, "ValidCommands", NULL);
+	p = ldap_attrib(ld, e, FTP_LDAP_VALID_COMMANDS, NULL);
 	if(NULL != p) {
 		cmds_set_allow(p);
 	}
Index: ftp-ldap.h
===================================================================
RCS file: /data/cvs/CVS-PSUITE/PROXY-SUITE/ftp-proxy/ftp-ldap.h,v
retrieving revision 1.4.2.1
diff -u -p -r1.4.2.1 ftp-ldap.h
--- ftp-ldap.h	7 May 2003 11:09:27 -0000	1.4.2.1
+++ ftp-ldap.h	5 Aug 2005 01:52:24 -0000
@@ -43,6 +43,22 @@
 
 int  ldap_setup_user(CONTEXT *ctx, char *who, char *pwd);
 
+/*
+** LDAP attribute names useable as per-user profile data
+*/
+#define FTP_LDAP_DESTINATION_ADDRESS        "DestinationAddress"
+#define FTP_LDAP_DESTINATION_PORT           "DestinationPort"
+#define FTP_LDAP_DESTINATION_TRANSFER_MODE  "DestinationTransferMode"
+#define FTP_LDAP_DESTINATION_MIN_PORT       "DestinationMinPort"
+#define FTP_LDAP_DESTINATION_MAX_PORT       "DestinationMaxPort"
+#define FTP_LDAP_ACTIVE_MIN_DATA_PORT       "ActiveMinDataPort"
+#define FTP_LDAP_ACTIVE_MAX_DATA_PORT       "ActiveMaxDataPort"
+#define FTP_LDAP_PASSIVE_MIN_DATA_PORT      "PassiveMinDataPort"
+#define FTP_LDAP_PASSIVE_MAX_DATA_PORT      "PassiveMaxDataPort"
+#define FTP_LDAP_VALID_COMMANDS             "ValidCommands"
+#define FTP_LDAP_SAME_ADDRESS               "SameAddress"
+#define FTP_LDAP_TIME_OUT                   "TimeOut"
+
 
 /* ------------------------------------------------------------ */
 


--DBIVS5p969aUjpLe
Content-Type: text/plain; charset=us-ascii

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
--DBIVS5p969aUjpLe--