#include "adm.h"
#include "adm_proto.h"
+#if HAVE_SRAND48
+#define SRAND srand48
+#define RAND lrand48
+#define RAND_TYPE long
+#endif /* HAVE_SRAND48 */
+
+#if !defined(RAND_TYPE) && defined(HAVE_SRAND)
+#define SRAND srand
+#define RAND rand
+#define RAND_TYPE int
+#endif /* !defined(RAND_TYPE) && defined(HAVE_SRAND) */
+
+#if !defined(RAND_TYPE) && defined(HAVE_SRANDOM)
+#define SRAND srandom
+#define RAND random
+#define RAND_TYPE long
+#endif /* !defined(RAND_TYPE) && defined(HAVE_SRANDOM) */
+
+#if !defined(RAND_TYPE)
+There is no random number generator.
+#endif /* !defined(RAND_TYPE) */
+
/*
* Generate a random event that has an a/b chance of succeeding
*/
-#define RANDOM_EVENT(a,b) ((random() % b) < a)
+#define RANDOM_EVENT(a,b) ((RAND() % b) < a)
/* Define probabilities of generating each attribute type */
#define PASSWORD_EVENT RANDOM_EVENT(3,5)
#define KVNO_EVENT RANDOM_EVENT(2,5)
/* Do password on set */
if (isrand) {
if (PASSWORD_EVENT) {
- pwlen = 9 + (random() % 56);
+ pwlen = 9 + (RAND() % 56);
*pwdp = (char *) malloc(pwlen);
for (i=0; i<pwlen-1; i++) {
- (*pwdp)[i] = random() % 128;
+ (*pwdp)[i] = RAND() % 128;
while (!isalnum((int) (*pwdp)[i]))
- (*pwdp)[i] = random() % 128;
+ (*pwdp)[i] = RAND() % 128;
}
(*pwdp)[pwlen-1] = '\0';
*validp |= KRB5_ADM_M_PASSWORD;
/* Do kvno */
if (isrand) {
if (KVNO_EVENT) {
- dbentp->kvno = random();
+ dbentp->kvno = RAND();
*validp |= KRB5_ADM_M_KVNO;
}
}
/* Do maxlife */
if (isrand) {
if (MAXLIFE_EVENT) {
- dbentp->max_life = random();
+ dbentp->max_life = RAND();
*validp |= KRB5_ADM_M_MAXLIFE;
}
}
/* Do maxrenewlife */
if (isrand) {
if (MAXRENEWLIFE_EVENT) {
- dbentp->max_renewable_life = random();
+ dbentp->max_renewable_life = RAND();
*validp |= KRB5_ADM_M_MAXRENEWLIFE;
}
}
/* Do expiration */
if (isrand) {
if (EXPIRATION_EVENT) {
- dbentp->expiration = random();
+ dbentp->expiration = RAND();
*validp |= KRB5_ADM_M_EXPIRATION;
}
}
/* Do pw_expiration */
if (isrand) {
if (PWEXPIRATION_EVENT) {
- dbentp->pw_expiration = random();
+ dbentp->pw_expiration = RAND();
*validp |= KRB5_ADM_M_PWEXPIRATION;
}
}
/* Do flags */
if (isrand) {
if (FLAGS_EVENT) {
- dbentp->attributes = random();
+ dbentp->attributes = RAND();
*validp |= KRB5_ADM_M_FLAGS;
}
}
/* Do salts */
if (isrand) {
if (SALT_EVENT) {
- dbentp->salt_type = (random() % 1);
- dbentp->alt_salt_type = (random() % 1);
+ dbentp->salt_type = (RAND() % 1);
+ dbentp->alt_salt_type = (RAND() % 1);
*validp |= KRB5_ADM_M_SALTTYPE;
}
}
/* Do mkvno */
if (isrand) {
if (MKVNO_EVENT) {
- dbentp->mkvno = random();
+ dbentp->mkvno = RAND();
*validp |= KRB5_ADM_M_MKVNO;
}
}
/* Do lastpwchange */
if (isrand) {
if (LASTPWCHANGE_EVENT) {
- dbentp->last_pwd_change = random();
+ dbentp->last_pwd_change = RAND();
*validp |= KRB5_ADM_M_LASTPWCHANGE;
}
}
/* Do lastsuccess */
if (isrand) {
if (LASTSUCCESS_EVENT) {
- dbentp->last_success = random();
+ dbentp->last_success = RAND();
*validp |= KRB5_ADM_M_LASTSUCCESS;
}
}
/* Do lastfailed */
if (isrand) {
if (LASTFAILED_EVENT) {
- dbentp->last_failed = random();
+ dbentp->last_failed = RAND();
*validp |= KRB5_ADM_M_LASTFAILED;
}
}
/* Do failcount */
if (isrand) {
if (FAILCOUNT_EVENT) {
- dbentp->fail_auth_count = random();
+ dbentp->fail_auth_count = RAND();
*validp |= KRB5_ADM_M_FAILCOUNT;
}
}
/* Do mod_date */
if (isrand) {
if (MODDATE_EVENT) {
- dbentp->mod_date = random();
+ dbentp->mod_date = RAND();
*validp |= KRB5_ADM_M_MODDATE;
}
}
if (is_set) {
/* Only 25% may fail at most */
- if (isrand && ((random() % 100) < 75)) {
+ if (isrand && ((RAND() % 100) < 75)) {
*validp &= KRB5_ADM_M_SET_VALID;
}
#ifdef notdef
}
else {
/* Only 25% may fail at most */
- if (isrand && ((random() % 100) < 75))
+ if (isrand && ((RAND() % 100) < 75))
*validp &= KRB5_ADM_M_GET_VALID;
*expectp = ((*validp & ~KRB5_ADM_M_GET_VALID) != 0) ? 1 : 0;
}
kret = ENOMEM;
}
- krb5_xfree(kcontext);
+ krb5_free_context(kcontext);
if (verbose) {
printf("* End %s ", title);
if (isrand)
programname = argv[0];
now = time((time_t *) NULL);
- srandom((unsigned) now);
+ SRAND((RAND_TYPE) now);
while ((option = getopt(argc, argv, "r:v")) != EOF) {
switch (option) {
case 'r':
#include "adm.h"
#include "adm_proto.h"
+#if HAVE_SRAND48
+#define SRAND srand48
+#define RAND lrand48
+#define RAND_TYPE long
+#endif /* HAVE_SRAND48 */
+
+#if !defined(RAND_TYPE) && defined(HAVE_SRAND)
+#define SRAND srand
+#define RAND rand
+#define RAND_TYPE int
+#endif /* !defined(RAND_TYPE) && defined(HAVE_SRAND) */
+
+#if !defined(RAND_TYPE) && defined(HAVE_SRANDOM)
+#define SRAND srandom
+#define RAND random
+#define RAND_TYPE long
+#endif /* !defined(RAND_TYPE) && defined(HAVE_SRANDOM) */
+
+#if !defined(RAND_TYPE)
+There is no random number generator.
+#endif /* !defined(RAND_TYPE) */
+
/*
* Generate a principal name.
*/
compsize[i] = 0;
complist[i] = (char *) NULL;
}
- ncomps = 2 + (random() % 7);
+ ncomps = 2 + (RAND() % 7);
totsize = 0;
for (i=0; i<ncomps; i++) {
- compsize[i] = 1 + (random() % 32);
+ compsize[i] = 1 + (RAND() % 32);
complist[i] = (char *) malloc(compsize[i]+1);
if (complist[i]) {
for (j=0; j<compsize[i]; j++) {
- (complist[i])[j] = random() % 128;
+ (complist[i])[j] = RAND() % 128;
while (!isalnum((int) (complist[i])[j]))
- (complist[i])[j] = random() % 128;
+ (complist[i])[j] = RAND() % 128;
}
(complist[i])[compsize[i]] = '\0';
totsize += (compsize[i] + 1);
size_t keylen;
int i;
- keylen = 4 + (random() % 64);
+ keylen = 4 + (RAND() % 64);
ktentp->key.contents = (krb5_octet *) malloc(keylen);
if (ktentp->key.contents) {
ktentp->key.length = keylen;
for (i=0; i<keylen; i++)
- ktentp->key.contents[i] = random() & 255;
+ ktentp->key.contents[i] = RAND() & 255;
}
}
else {
princname,
&ktentp->principal)
) {
- ktentp->vno = (isrand) ? random() : 1;
+ ktentp->vno = (isrand) ? RAND() : 1;
gen_key(ktentp, isrand);
+ free(princname);
}
}
/* Cleanup */
if (in_ktent->principal)
krb5_free_principal(kcontext, in_ktent->principal);
+ if (in_ktent->key.contents)
+ free(in_ktent->key.contents);
free(in_ktent);
if (out_ktent->principal)
krb5_free_principal(kcontext, out_ktent->principal);
+ if (out_ktent->key.contents)
+ free(out_ktent->key.contents);
free(out_ktent);
}
else {
kret = ENOMEM;
}
- krb5_xfree(kcontext);
+ krb5_free_context(kcontext);
if (verbose) {
printf("* End %s ", title);
if (isrand)
programname = argv[0];
now = time((time_t *) NULL);
- srandom((unsigned) now);
+ SRAND((RAND_TYPE) now);
while ((option = getopt(argc, argv, "r:v")) != EOF) {
switch (option) {
case 'r':