* Utility to_upper

* LDAP plugin can use a scope
Initial
Stephane Bortzmeyer 20 years ago
parent 4779000995
commit 2f6d8d9b17

@ -69,7 +69,6 @@ char *
init (const int argc, const char **argv)
{
int value;
int c;
char *hostname;
char *msg = malloc (256);
char *type_name, *upper_type_name = NULL;
@ -102,15 +101,12 @@ init (const int argc, const char **argv)
request = (char *) poptGetArg (dns_poptcon);
if (request == NULL)
dns_usage ("Mandatory request missing");
if ((type_name == NULL) || !strcmp(type_name, ""))
if ((type_name == NULL) || !strcmp (type_name, ""))
type = T_A;
else
{
{
upper_type_name = to_upper (type_name);
/* TODO: a better algorithm. Use dns_rdatatype_fromtext in BIND ? */
upper_type_name = (char *) malloc(strlen(type_name));
for (c=0; c<strlen(type_name); c++)
upper_type_name[c] = toupper(type_name[c]);
upper_type_name[strlen(type_name)] = '\0';
if (!strcmp (upper_type_name, "A"))
type = T_A;
else if (!strcmp (upper_type_name, "AAAA"))
@ -129,7 +125,7 @@ init (const int argc, const char **argv)
type = T_PTR;
else if (!strcmp (upper_type_name, "TXT"))
type = T_TXT;
else
else
dns_usage ("Unknown type");
}
return "domain";

@ -11,6 +11,7 @@
const char *request = NULL;
const char *base = NULL;
int scope = LDAP_SCOPE_BASE;
const char *hostname;
unsigned int port = 0;
LDAP *session;
@ -34,12 +35,15 @@ init (const int argc, const char **argv,
{
int value;
char *msg;
char *scope_string = NULL;
/* popt variables */
struct poptOption options[] = {
{"request", 'r', POPT_ARG_STRING, &request, 0,
"Request (filter) to send to the LDAP server", 'r'},
{"base", 'b', POPT_ARG_STRING, &base, 0,
"Base of the LDAP tree", 'b'},
{"scope", 's', POPT_ARG_STRING, &scope_string, 0,
"Scope of the search in the LDAP tree (sub, one or base)", 's'},
{"port", 'p', POPT_ARG_INT, &port, 0,
"TCP port to connect to the LDAP server", 'p'},
POPT_AUTOHELP POPT_TABLEEND
@ -66,6 +70,18 @@ init (const int argc, const char **argv,
base = "";
if (request == NULL || !strcmp (request, ""))
request = "(objectclass=*)";
if (scope_string != NULL)
{
scope_string = to_upper (scope_string);
if (!strcmp (scope_string, "BASE"))
scope = LDAP_SCOPE_BASE;
else if (!strcmp (scope_string, "SUB"))
scope = LDAP_SCOPE_SUBTREE;
else if (!strcmp (scope_string, "ONE"))
scope = LDAP_SCOPE_ONELEVEL;
else
err_quit ("Invalid scope \"%s\"", scope);
}
return "ldap";
}
@ -84,8 +100,7 @@ execute ()
{
int result;
LDAPMessage *response;
result = ldap_search_s (session, base, LDAP_SCOPE_BASE, /* TODO: allow to set the scope */
request, NULL, /* Return all attributes */
result = ldap_search_s (session, base, scope, request, NULL, /* Return all attributes */
0, /* Return attribute types *and* values */
&response);
if (result != 0)

@ -7,6 +7,7 @@
#define STATES 32
#include <time.h>
#include <ctype.h>
char *
random_string (unsigned length)
@ -36,6 +37,18 @@ random_string (unsigned length)
}
char *
to_upper (char *input)
{
int c;
char *result;
result = (char *) malloc (strlen (input));
for (c = 0; c < strlen (input); c++)
result[c] = toupper (input[c]);
result[strlen (input)] = '\0';
return result;
}
/*
* tvsub -- Subtract 2 timeval structs: out = out - in. Out is assumed to be
* >= in. Comes from the bing program.

Loading…
Cancel
Save