Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/rsearch
In directory
cvs1.fedora.phx.redhat.com:/tmp/cvs-serv3879/ldap/servers/slapd/tools/rsearch
Modified Files:
rsearch.c rsearch.h searchthread.c
Log Message:
Resolves: 470611
Summary: Enhanced rsearch to allow user filter and password to be configurable
(contributed by telackey(a)bozemanpass.com).
Index: rsearch.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/rsearch/rsearch.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- rsearch.c 8 Oct 2008 17:29:04 -0000 1.5
+++ rsearch.c 29 Jan 2009 17:32:21 -0000 1.6
@@ -54,6 +54,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
+#include <string.h>
#ifdef XP_UNIX
#include <unistd.h>
#endif
@@ -104,6 +106,8 @@
"-C num -- take num samples, then stop\n"
"-R num -- drop connection & reconnect every num searches\n"
"-x -- Use -B file for binding; ignored if -B is not given\n"
+ "-W -- Password to use when binding with -B. Default is the
UID.\n"
+ "-U -- Filter to use with binding file. Ignored if -x is not given.
Default is '(uid=%%s)'.\n"
"\n",
DEFAULT_HOSTNAME, DEFAULT_PORT,
LDAP_SCOPE_BASE, LDAP_SCOPE_ONELEVEL, LDAP_SCOPE_SUBTREE,
@@ -223,6 +227,8 @@
char *attrFile = 0;
char *bindDN = NULL;
char *bindPW = NULL;
+char *userPW = NULL;
+char *uidFilter = NULL;
char **attrToReturn = 0;
char *attrList = 0;
Operation opType = op_search;
@@ -253,7 +259,7 @@
}
while ((ch = getopt(argc, argv,
- "B:a:j:i:h:s:f:p:o:t:T:D:w:n:A:S:C:R:bvlyqmMcduNLHx?V"))
+ "U:W:B:a:j:i:h:s:f:p:o:t:T:D:w:n:A:S:C:R:bvlyqmMcduNLHx?V"))
!= EOF)
switch (ch) {
case 'h':
@@ -359,6 +365,12 @@
case 'x':
useBFile = 1;
break;
+ case 'W':
+ userPW = optarg;
+ break;
+ case 'U':
+ uidFilter = optarg;
+ break;
case 'a':
if (optarg[0] == '?') {
usage_A();
@@ -387,6 +399,11 @@
argc -= optind;
argv += optind;
+ if (uidFilter && NULL == strstr(uidFilter, "%s")) {
+ printf("rsearch: invalid UID filter - must contain %%s, eg, (uid=%%s)\n");
+ usage();
+ }
+
PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 0);
ntable = nt_new(0);
@@ -487,13 +504,20 @@
cumrate += rate;
if ((numThreads > 1) || (!verbose)) {
if (!quiet) {
+ char tbuf[18];
+ struct tm* now;
+ time_t lt;
+
+ time(<);
+ now = localtime(<);
+ strftime(tbuf, sizeof(tbuf), "%Y%m%d %H:%M:%S", now);
if (showRunningAvg)
- printf("Rate: %7.2f/thr (cumul rate: %7.2f/thr)\n",
- rate, cumrate/(double)counter);
+ printf("%s - Rate: %7.2f/thr (cumul rate: %7.2f/thr)\n",
+ tbuf, rate, cumrate/(double)counter);
else
- printf("Rate: %7.2f/thr (%6.2f/sec =%7.4fms/op), "
+ printf("%s - Rate: %7.2f/thr (%6.2f/sec =%7.4fms/op), "
"total:%6u (%d thr)\n",
- rate, val, (double)1000.0/val, total, numThreads);
+ tbuf, rate, val, (double)1000.0/val, total, numThreads);
}
}
if (countLimit && (counter >= countLimit)) {
Index: rsearch.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/rsearch/rsearch.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- rsearch.h 1 Aug 2007 17:51:10 -0000 1.4
+++ rsearch.h 29 Jan 2009 17:32:21 -0000 1.5
@@ -69,6 +69,8 @@
/**/ extern char *nameFile;
extern char *bindDN;
extern char *bindPW;
+extern char *userPW;
+extern char *uidFilter;
extern char **attrToReturn;
/**/ extern char *attrList;
extern Operation opType;
Index: searchthread.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/rsearch/searchthread.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- searchthread.c 8 Oct 2008 17:29:04 -0000 1.6
+++ searchthread.c 29 Jan 2009 17:32:21 -0000 1.7
@@ -90,7 +90,6 @@
st->alive = 1;
st->lock = PR_NewLock();
st->retry = 0;
- srand(time(0));
return st;
}
@@ -106,6 +105,11 @@
return st->id;
}
+void st_seed(SearchThread *st) {
+ time_t t = time(0);
+ t -= st->id * 1000;
+ srand((unsigned int)t);
+}
static void st_enableTCPnodelay(SearchThread *st)
{
@@ -143,12 +147,12 @@
st->soc = -1;
}
-static int st_bind_core(SearchThread *st, LDAP **ld, char *dn, char *uid)
+static int st_bind_core(SearchThread *st, LDAP **ld, char *dn, char *pw)
{
int ret = 0;
int retry = 0;
while (1) {
- ret = ldap_simple_bind_s(*ld, dn, uid);
+ ret = ldap_simple_bind_s(*ld, dn, pw);
if (LDAP_SUCCESS == ret) {
break;
} else if (LDAP_CONNECT_ERROR == ret && retry < 10) {
@@ -156,7 +160,7 @@
} else {
fprintf(stderr, "T%d: failed to bind, ldap_simple_bind_s"
"(%s, %s) returned 0x%x (errno %d)\n",
- st->id, dn, uid, ret, errno);
+ st->id, dn, pw, ret, errno);
*ld = NULL;
return 0;
}
@@ -188,30 +192,33 @@
if (opType != op_delete && opType != op_modify && opType !=
op_idxmodify &&
sdattable && sdt_getlen(sdattable) > 0) {
int e;
- char *dn, *uid;
+ char *dn, *uid, *upw;
do {
e = sdt_getrand(sdattable);
} while (e < 0);
dn = sdt_dn_get(sdattable, e);
uid = sdt_uid_get(sdattable, e);
+ /* in this test, assuming uid == password unless told otherwise */
+ upw = (userPW) ? userPW : uid;
if (useBFile) {
- /* in this test, assuming uid == password */
+
if (dn) {
- if (0 == st_bind_core(st, &(st->ld), dn, uid)) {
+ if (0 == st_bind_core(st, &(st->ld), dn, upw)) {
return 0;
}
} else if (uid) {
char filterBuffer[100];
char *pFilter;
+ char *filterTemplate = (uidFilter) ? uidFilter : "(uid=%s)";
struct timeval timeout;
int scope = LDAP_SCOPE_SUBTREE, attrsOnly = 0;
LDAPMessage *result;
int retry = 0;
pFilter = filterBuffer;
- sprintf(filterBuffer, "(uid=%s)", uid);
+ sprintf(filterBuffer, filterTemplate, uid);
timeout.tv_sec = 3600;
timeout.tv_usec = 0;
while (1) {
@@ -230,7 +237,7 @@
}
dn = ldap_get_dn(st->ld2, result);
- if (0 == st_bind_core(st, &(st->ld), dn, uid)) {
+ if (0 == st_bind_core(st, &(st->ld), dn, upw)) {
return 0;
}
} else {
@@ -239,7 +246,7 @@
return 0;
}
} else {
- if (0 == st_bind_core(st, &(st->ld), dn, uid)) {
+ if (0 == st_bind_core(st, &(st->ld), dn, upw)) {
return 0;
}
}
@@ -504,6 +511,7 @@
int notBound = 1, res = LDAP_SUCCESS, searches = 0;
PRUint32 span;
+ st_seed(st);
st->alive = 1;
st->ld = 0;
while (1) {
@@ -544,6 +552,10 @@
return;
}
}
+ else {
+ /* Fake status for NOOP */
+ res = LDAP_SUCCESS;
+ }
if (LDAP_SUCCESS == res) {
st->retry = 0;
} else if (LDAP_CONNECT_ERROR == res && st->retry < 10) {