1 /* sasldblistusers.c -- list users in sasldb
2 * $Id: sasldblistusers.c,v 1.22 2003/10/03 20:30:14 rjs3 Exp $
7 * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. The name "Carnegie Mellon University" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For permission or any other legal
24 * details, please contact
25 * Office of Technology Transfer
26 * Carnegie Mellon University
28 * Pittsburgh, PA 15213-3890
29 * (412) 268-4387, fax: (412) 268-7395
30 * tech-transfer@andrew.cmu.edu
32 * 4. Redistributions of any form whatsoever must retain the following
34 * "This product includes software developed by Computing Services
35 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
37 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
38 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
40 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
41 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
42 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
43 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
56 #include "../sasldb/sasldb.h"
60 __declspec(dllimport) char *optarg;
61 __declspec(dllimport) int optind;
64 /* Cheating to make the utils work out right */
65 LIBSASL_VAR const sasl_utils_t *sasl_global_utils;
67 char *sasldb_path = SASL_DB_PATH;
68 const char *progname = NULL;
70 int good_getopt(void *context __attribute__((unused)),
71 const char *plugin_name __attribute__((unused)),
76 if (sasldb_path && !strcmp(option, "sasldb_path")) {
77 *result = sasldb_path;
79 *len = strlen(sasldb_path);
86 static struct sasl_callback goodsasl_cb[] = {
87 { SASL_CB_GETOPT, &good_getopt, NULL },
88 { SASL_CB_LIST_END, NULL, NULL }
91 int main(int argc, char **argv)
97 int display_usage = 0;
98 const char *sasl_implementation;
105 progname = "sasldblistusers2";
107 progname = strrchr(argv[0], HIER_DELIMITER);
114 /* A single parameter not starting with "-" denotes sasldb to use */
115 if ((argc == 2) && argv[1][0] != '-') {
116 sasldb_path = argv[1];
120 while ((c = getopt(argc, argv, "vf:h?")) != EOF) {
123 sasldb_path = optarg;
130 sasl_version (&sasl_implementation, &libsasl_version);
131 libsasl_major = libsasl_version >> 24;
132 libsasl_minor = (libsasl_version >> 16) & 0xFF;
133 libsasl_step = libsasl_version & 0xFFFF;
135 (void)fprintf(stderr, "\nThis product includes software developed by Computing Services\n"
136 "at Carnegie Mellon University (http://www.cmu.edu/computing/).\n\n"
137 "Built against SASL API version %u.%u.%u\n"
138 "LibSasl version %u.%u.%u by \"%s\"\n",
139 SASL_VERSION_MAJOR, SASL_VERSION_MINOR, SASL_VERSION_STEP,
140 libsasl_major, libsasl_minor, libsasl_step, sasl_implementation);
156 "\nThis product includes software developed by Computing Services\n"
157 "at Carnegie Mellon University (http://www.cmu.edu/computing/).\n\n");
159 fprintf(stderr, "%s: usage: %s [-v] [[-f] sasldb]\n",
161 fprintf(stderr, "\t-f sasldb\tuse given file as sasldb\n"
162 "\t-v\tprint version numbers and exit\n");
164 fprintf(stderr, "Unrecognized command line option\n");
170 result = sasl_server_init(goodsasl_cb, "sasldblistusers");
171 if(result != SASL_OK) {
172 fprintf(stderr, "Couldn't initialize server API\n");
176 result = sasl_server_new("sasldb",
185 if(_sasl_check_db(sasl_global_utils, conn) != SASL_OK) {
186 fprintf(stderr, "check_db unsuccessful\n");
190 if(_sasldb_listusers (sasl_global_utils, conn, NULL, NULL) != SASL_OK) {
191 fprintf(stderr, "listusers failed\n");