static char *argv0 = 0;
#include <stdio.h>
#include <ctype.h>
#include "../apple_membership.c"
#ifndef APPLE_CHAT_SACL_NAME
#define APPLE_CHAT_SACL_NAME "chat"
#endif
int
membership_test(int iterations, const char *username_fmt, const char *service)
{
int i;
int success = 0;
if (service == 0)
service = APPLE_CHAT_SACL_NAME;
for (i = 1; i <= iterations; ++i) {
char username[1024];
snprintf(username, sizeof(username), username_fmt, i, i, i, i, i, i);
if (od_auth_check_service_membership(username, service) != 0)
++success;
}
return success;
}
int
usage()
{
fprintf(stderr, "usage: %s iterations username [service]\n", argv0);
fprintf(stderr, " username is passed to sprintf, where %%d is the index (1..iterations)\n");
fprintf(stderr, " (eg %s 1000 'testuser%%d')\n", argv0);
exit(1);
}
int
main(int argc, const char * argv[])
{
argv0 = (char*)argv[0];
if (strrchr(argv0, '/'))
argv0 = strrchr(argv0, '/') + 1;
if (argc != 3 && argc != 4)
usage();
if (! isdigit(argv[1][0]))
usage();
int iterations = atoi(argv[1]);
fprintf(stderr, "Starting %d iterations\n", iterations);
int success = membership_test(iterations, argv[2], (argc == 4) ? argv[3] : 0);
printf("%s: %d successful checks (of %d)\n", argv0, success, iterations);
return 0;
}