From 690a4258d23d68b74b3ade5fde0770e20e75948a Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Apr 14 2011 22:58:01 +0000 Subject: -new 'listnicks' tool --- diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am index b248d3b..fe2d363 100644 --- a/tests/tools/Makefile.am +++ b/tests/tools/Makefile.am @@ -1,4 +1,5 @@ AM_CFLAGS = $(TALLOC_CFLAGS) $(TEVENT_CFLAGS) $(DBUS_CFLAGS) \ -I$(builddir)/../../src -noinst_PROGRAMS = keyiread keygen csrgen submit certread certsave oid2name name2oid iterate prefs notty dates +listnicks_CFLAGS = $(AM_CFLAGS) $(NSS_CFLAGS) +noinst_PROGRAMS = keyiread keygen csrgen submit certread certsave oid2name name2oid iterate prefs notty dates listnicks LDADD = ../../src/libcm.a $(srcdir)/../../src/env-system.c @OPENSSL_LIBS@ @CERTMONGER_LIBS@ @KRB5_LIBS@ @UUID_LIBS@ diff --git a/tests/tools/listnicks.c b/tests/tools/listnicks.c new file mode 100644 index 0000000..b154842 --- /dev/null +++ b/tests/tools/listnicks.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2011 Red Hat, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../../src/config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "../../src/log.h" +#include "../../src/store.h" +#include "../../src/store-int.h" + +int +main(int argc, char **argv) +{ + struct cm_store_entry *entry; + int i, what; + void *parent; + CERTCertNicknames *names; + SECStatus error; + + cm_log_set_method(cm_log_stderr); + cm_log_set_level(1); + parent = talloc_new(NULL); + if (argc > 1) { + entry = cm_store_files_entry_read(parent, argv[1]); + if (entry == NULL) { + printf("Error reading %s: %s.\n", argv[1], + strerror(errno)); + return 1; + } + } else { + printf("Specify an entry file as the single argument.\n"); + return 1; + } + if (entry->cm_cert_storage_type != cm_cert_storage_nssdb) { + cm_log(1, "Storage type is not NSSDB.\n"); + return 1; + } + /* Open the database. */ + error = NSS_Init(entry->cm_cert_storage_location); + if (error != SECSuccess) { + cm_log(1, "Unable to open NSS database.\n"); + _exit(1); + } + /* Walk the list of names, if we got one. */ + what = (argc > 2) ? atoi(argv[2]) : SEC_CERT_NICKNAMES_ALL; + names = CERT_GetCertNicknames(CERT_GetDefaultCertDB(), what, NULL); + if (names != NULL) { + printf("%d: ", what); + for (i = 0; i < names->numnicknames; i++) { + printf("\"%s\"", names->nicknames[i]); + if (i > 0) { + printf(","); + } + } + printf("\n"); + fflush(NULL); + CERT_FreeNicknames(names); + } + talloc_free(parent); + if (NSS_Shutdown() != SECSuccess) { + cm_log(1, "Error shutting down NSS.\n"); + } + return 0; +}