summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBret Lambert <blambert@cvs.openbsd.org>2010-02-06 08:04:46 +0000
committerBret Lambert <blambert@cvs.openbsd.org>2010-02-06 08:04:46 +0000
commit10a30e33d830583d56fe94e3b21a97554400b740 (patch)
tree2be1234199f82faa06154c480e348524786c1a14
parent00e9ce494559367edd5aa8939cad5c6219b393d8 (diff)
Simplify LDAP URL handling (currently unused):
instead of strdup()'ing multiple values from an already strdup'ed buffer (none of which were checked for NULL upon return, which is also fixed in this), just use a buffer attached to the aldap_url struct. Add an aldap_search_url() function, which is a wrapper around aldap_parse_url and aldap_search. Finally, since the URL bits are unused, wrap them in #if 0 for now. ok pyr@, whose heart was a little broken by the #if 0 (temporary, I swear!)
-rw-r--r--usr.sbin/ypldap/aldap.c63
-rw-r--r--usr.sbin/ypldap/aldap.h8
2 files changed, 48 insertions, 23 deletions
diff --git a/usr.sbin/ypldap/aldap.c b/usr.sbin/ypldap/aldap.c
index 70c096a477a..811a8b88f76 100644
--- a/usr.sbin/ypldap/aldap.c
+++ b/usr.sbin/ypldap/aldap.c
@@ -1,5 +1,5 @@
-/* $Id: aldap.c,v 1.20 2009/07/08 13:13:17 blambert Exp $ */
-/* $OpenBSD: aldap.c,v 1.20 2009/07/08 13:13:17 blambert Exp $ */
+/* $Id: aldap.c,v 1.21 2010/02/06 08:04:45 blambert Exp $ */
+/* $OpenBSD: aldap.c,v 1.21 2010/02/06 08:04:45 blambert Exp $ */
/*
* Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org>
@@ -60,7 +60,6 @@ aldap_close(struct aldap *al)
return (0);
}
-
struct aldap *
aldap_init(int fd)
{
@@ -444,26 +443,23 @@ aldap_free_entry(char **values)
return (1);
}
+#if 0
void
aldap_free_url(struct aldap_url *lu)
{
- int i;
- free(lu->host);
- free(lu->dn);
- for (i = 0; i < MAXATTR && lu->attributes[i] != NULL; i++) {
- free(lu->attributes[i]);
- }
+ free(lu->buffer);
free(lu->filter);
}
int
aldap_parse_url(char *url, struct aldap_url *lu)
{
- char *dupstr, *p, *forward, *forward2;
+ char *p, *forward, *forward2;
const char *errstr = NULL;
int i;
- p = dupstr = strdup(url);
+ if ((lu->buffer = p = strdup(url)) == NULL)
+ return (-1);
/* protocol */
if (strncasecmp(LDAP_URL, p, strlen(LDAP_URL)) != 0)
@@ -488,7 +484,7 @@ aldap_parse_url(char *url, struct aldap_url *lu)
/* fail if no host is given */
if (strlen(p) == 0)
goto fail;
- lu->host = strdup(p);
+ lu->host = p;
if (forward == NULL)
goto done;
/* p is assigned either a pointer to a character or to '\0' */
@@ -499,7 +495,7 @@ aldap_parse_url(char *url, struct aldap_url *lu)
/* dn */
if ((forward = strchr(p, '?')) != NULL)
*forward = '\0';
- lu->dn = strdup(p);
+ lu->dn = p;
if (forward == NULL)
goto done;
/* p is assigned either a pointer to a character or to '\0' */
@@ -514,11 +510,11 @@ aldap_parse_url(char *url, struct aldap_url *lu)
if ((forward2 = strchr(p, ',')) == NULL) {
if (strlen(p) == 0)
break;
- lu->attributes[i] = strdup(p);
+ lu->attributes[i] = p;
break;
}
*forward2 = '\0';
- lu->attributes[i] = strdup(p);
+ lu->attributes[i] = p;
p = ++forward2;
}
if (forward == NULL)
@@ -537,6 +533,8 @@ aldap_parse_url(char *url, struct aldap_url *lu)
lu->scope = LDAP_SCOPE_ONELEVEL;
else if (strcmp(p, "sub") == 0)
lu->scope = LDAP_SCOPE_SUBTREE;
+ else
+ goto fail;
if (forward == NULL)
goto done;
p = ++forward;
@@ -544,18 +542,40 @@ aldap_parse_url(char *url, struct aldap_url *lu)
goto done;
/* filter */
- if (p == NULL)
- goto done;
- lu->filter = strdup(p);
-
+ if (p)
+ lu->filter = p;
done:
- free(dupstr);
return (1);
fail:
- free(dupstr);
+ free(lu->buffer);
+ lu->buffer = NULL;
return (-1);
}
+int
+aldap_search_url(struct aldap *ldap, char *url, int typesonly, int sizelimit,
+ int timelimit)
+{
+ struct aldap_url *lu;
+
+ if ((lu = calloc(1, sizeof(*lu))) == NULL)
+ return (-1);
+
+ if (aldap_parse_url(url, lu))
+ goto fail;
+
+ if (aldap_search(ldap, lu->dn, lu->scope, lu->filter, lu->attributes,
+ typesonly, sizelimit, timelimit) == -1)
+ goto fail;
+
+ aldap_free_url(lu);
+ return (ldap->msgid);
+fail:
+ aldap_free_url(lu);
+ return (-1);
+}
+#endif /* 0 */
+
/*
* internal functions
*/
@@ -1114,6 +1134,7 @@ parseval(char *p, size_t len)
return buffer;
}
+
int
aldap_get_errno(struct aldap *a, const char **estr)
{
diff --git a/usr.sbin/ypldap/aldap.h b/usr.sbin/ypldap/aldap.h
index 35d81dbd3cd..d4238cb42ee 100644
--- a/usr.sbin/ypldap/aldap.h
+++ b/usr.sbin/ypldap/aldap.h
@@ -1,5 +1,5 @@
-/* $Id: aldap.h,v 1.6 2009/01/27 11:33:22 aschrijver Exp $ */
-/* $OpenBSD: aldap.h,v 1.6 2009/01/27 11:33:22 aschrijver Exp $ */
+/* $Id: aldap.h,v 1.7 2010/02/06 08:04:45 blambert Exp $ */
+/* $OpenBSD: aldap.h,v 1.7 2010/02/06 08:04:45 blambert Exp $ */
/*
* Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org>
@@ -72,6 +72,7 @@ struct aldap_url {
char *attributes[MAXATTR];
int scope;
char *filter;
+ char *buffer;
};
enum protocol_op {
@@ -195,8 +196,11 @@ char *aldap_get_dn(struct aldap_message *);
char *aldap_get_diagmsg(struct aldap_message *);
char **aldap_get_references(struct aldap_message *);
void aldap_free_references(char **values);
+#if 0
int aldap_parse_url(char *, struct aldap_url *);
void aldap_free_url(struct aldap_url *);
+int aldap_search_url(struct aldap *, char *, int, int, int);
+#endif
int aldap_count_entries(struct aldap_message *);
int aldap_match_entry(struct aldap_message *, char *, char ***);