+/* LIBLDAP url.c -- LDAP URL (RFC 2255) related routines */
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- */
-/* Portions
- * Copyright (c) 1996 Regents of the University of Michigan.
- * All rights reserved.
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2004 The OpenLDAP Foundation.
+ * All rights reserved.
*
- * LIBLDAP url.c -- LDAP URL (RFC 2255) related routines
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
*
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1996 Regents of the University of Michigan.
+ * All rights reserved.
+ */
+
+
+/*
* LDAP URLs look like this:
* ldap[is]://host:port[/[dn[?[attributes][?[scope][?[filter][?exts]]]]]]
*
return -1;
}
+int ldap_pvt_url_scheme_port( const char *scheme, int port )
+{
+ assert( scheme );
+
+ if( port ) return port;
+ if( scheme == NULL ) return port;
+
+ if( strcmp("ldap", scheme) == 0 ) {
+ return LDAP_PORT;
+ }
+
+ if( strcmp("ldapi", scheme) == 0 ) {
+ return -1;
+ }
+
+ if( strcmp("ldaps", scheme) == 0 ) {
+ return LDAPS_PORT;
+ }
+
+#ifdef LDAP_CONNECTIONLESS
+ if( strcmp("cldap", scheme) == 0 ) {
+ return LDAP_PORT;
+ }
+#endif
+
+ return -1;
+}
+
int
ldap_pvt_url_scheme2tls( const char *scheme )
{
if ( strcasecmp( p, "one" ) == 0 ) {
return LDAP_SCOPE_ONELEVEL;
- } else if ( strcasecmp( p, "onetree" ) == 0 ) {
+ } else if ( strcasecmp( p, "onelevel" ) == 0 ) {
return LDAP_SCOPE_ONELEVEL;
} else if ( strcasecmp( p, "base" ) == 0 ) {
};
if( u->lud_port ) {
- len+=6;
+ len += sizeof(":65535") - 1;
}
if( u->lud_host ) {
}
if ( q != NULL ) {
+ char *next;
+
*q++ = '\0';
ldap_pvt_hex_unescape( q );
return LDAP_URL_ERR_BADURL;
}
- ludp->lud_port = atoi( q );
+ ludp->lud_port = strtol( q, &next, 10 );
+ if ( next == NULL || next[0] != '\0' ) {
+ LDAP_FREE( url );
+ ldap_free_urldesc( ludp );
+ return LDAP_URL_ERR_BADURL;
+ }
}
ldap_pvt_hex_unescape( url );
urls = ldap_str2charray(url, sep);
if (urls == NULL)
- return LDAP_NO_MEMORY;
+ return LDAP_URL_ERR_MEM;
/* count the URLs... */
for (i = 0; urls[i] != NULL; i++) ;
*ludlist = ludp;
}
ldap_charray_free(urls);
- return LDAP_SUCCESS;
+ return LDAP_URL_SUCCESS;
}
int
}
}
if (p != NULL) {
+ char *next;
+
*p++ = 0;
ldap_pvt_hex_unescape(p);
- ludp->lud_port = atoi(p);
+ ludp->lud_port = strtol( p, &next, 10 );
+ if ( next == NULL || next[0] != '\0' ) {
+ return LDAP_PARAM_ERROR;
+ }
}
}
ldap_pvt_hex_unescape(ludp->lud_host);