Skip to content

Commit

Permalink
Modernize coding style of most client programs
Browse files Browse the repository at this point in the history
Adjust the style of kcpytkt, kdeltkt, kdestroy, kinit, klist, kpasswd,
and kvno to conform to current coding practices.

[ghudson@mit.edu: made additional style and naming changes; edited
commit message]
  • Loading branch information
mmattioli authored and greghudson committed May 24, 2017
1 parent 0f51214 commit b3df4f4
Show file tree
Hide file tree
Showing 8 changed files with 607 additions and 686 deletions.
48 changes: 22 additions & 26 deletions src/clients/kcpytkt/kcpytkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@
#include "k5-platform.h"

static char *prog;
static int quiet = 0;

static void xusage()
static void
xusage()
{
fprintf(stderr, "xusage: %s [-c from_ccache] [-e etype] [-f flags] dest_ccache service1 service2 ...\n", prog);
fprintf(stderr, "xusage: %s [-c from_ccache] [-e etype] [-f flags] "
"dest_ccache service1 service2 ...\n", prog);
exit(1);
}

int quiet = 0;
static void
do_kcpytkt(int argc, char *argv[], char *fromccachestr, char *etypestr,
int flags);

static void do_kcpytkt (int argc, char *argv[], char *fromccachestr, char *etypestr, int flags);

int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int option;
char *etypestr = 0;
char *fromccachestr = 0;
char *etypestr = NULL, *fromccachestr = NULL;
int flags = 0;

prog = strrchr(argv[0], '/');
prog = prog ? (prog + 1) : argv[0];
prog = (prog != NULL) ? prog + 1 : argv[0];

while ((option = getopt(argc, argv, "c:e:f:hq")) != -1) {
switch (option) {
Expand All @@ -49,34 +52,32 @@ int main(int argc, char *argv[])
}
}

if ((argc - optind) < 2)
if (argc - optind < 2)
xusage();

do_kcpytkt(argc - optind, argv + optind, fromccachestr, etypestr, flags);
return 0;
}

static void do_kcpytkt (int count, char *names[],
char *fromccachestr, char *etypestr, int flags)
static void
do_kcpytkt(int count, char *names[], const char *fromccachestr, char *etypestr,
int flags)
{
krb5_context context;
krb5_error_code ret;
int i, errors;
krb5_enctype etype;
krb5_ccache fromccache;
krb5_ccache destccache;
krb5_ccache fromccache, destccache;
krb5_principal me;
krb5_creds in_creds, out_creds;
int retflags;
int i, errors, retflags;
char *princ;

ret = krb5_init_context(&context);
if (ret) {
com_err(prog, ret, "while initializing krb5 library");
exit(1);
}

if (etypestr) {
if (etypestr != NULL) {
ret = krb5_string_to_enctype(etypestr, &etype);
if (ret) {
com_err(prog, ret, "while converting etype");
Expand All @@ -88,7 +89,7 @@ static void do_kcpytkt (int count, char *names[],
retflags = KRB5_TC_MATCH_SRV_NAMEONLY;
}

if (fromccachestr)
if (fromccachestr != NULL)
ret = krb5_cc_resolve(context, fromccachestr, &fromccache);
else
ret = krb5_cc_default(context, &fromccache);
Expand Down Expand Up @@ -118,9 +119,10 @@ static void do_kcpytkt (int count, char *names[],

ret = krb5_parse_name(context, names[i], &in_creds.server);
if (ret) {
if (!quiet)
if (!quiet) {
fprintf(stderr, "%s: %s while parsing principal name\n",
names[i], error_message(ret));
}
errors++;
continue;
}
Expand All @@ -140,24 +142,18 @@ static void do_kcpytkt (int count, char *names[],
if (ret) {
fprintf(stderr, "%s: %s while retrieving credentials\n",
princ, error_message(ret));

krb5_free_unparsed_name(context, princ);

errors++;
continue;
}

ret = krb5_cc_store_cred(context, destccache, &out_creds);

krb5_free_principal(context, in_creds.server);

if (ret) {
fprintf(stderr, "%s: %s while removing credentials\n",
princ, error_message(ret));

krb5_free_cred_contents(context, &out_creds);
krb5_free_unparsed_name(context, princ);

errors++;
continue;
}
Expand Down
37 changes: 18 additions & 19 deletions src/clients/kdeltkt/kdeltkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
#include "k5-platform.h"

static char *prog;
static int quiet = 0;

static void xusage()
static void
xusage()
{
fprintf(stderr, "xusage: %s [-c ccache] [-e etype] [-f flags] service1 service2 ...\n", prog);
fprintf(stderr, "xusage: %s [-c ccache] [-e etype] [-f flags] service1 "
"service2 ...\n", prog);
exit(1);
}

int quiet = 0;
static void
do_kdeltkt(int argc, char *argv[], char *ccachestr, char *etypestr, int flags);

static void do_kdeltkt (int argc, char *argv[], char *ccachestr, char *etypestr, int flags);

int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int option;
char *etypestr = 0;
char *ccachestr = 0;
char *etypestr = NULL, *ccachestr = NULL;
int flags = 0;

prog = strrchr(argv[0], '/');
prog = prog ? (prog + 1) : argv[0];
prog = (prog != NULL) ? prog + 1 : argv[0];

while ((option = getopt(argc, argv, "c:e:f:hq")) != -1) {
switch (option) {
Expand All @@ -49,15 +51,16 @@ int main(int argc, char *argv[])
}
}

if ((argc - optind) < 1)
if (argc - optind < 1)
xusage();

do_kdeltkt(argc - optind, argv + optind, ccachestr, etypestr, flags);
return 0;
}

static void do_kdeltkt (int count, char *names[],
char *ccachestr, char *etypestr, int flags)
static void
do_kdeltkt(int count, char *names[], const char *ccachestr, char *etypestr,
int flags)
{
krb5_context context;
krb5_error_code ret;
Expand All @@ -75,7 +78,7 @@ static void do_kdeltkt (int count, char *names[],
exit(1);
}

if (etypestr) {
if (etypestr != NULL) {
ret = krb5_string_to_enctype(etypestr, &etype);
if (ret) {
com_err(prog, ret, "while converting etype");
Expand Down Expand Up @@ -111,9 +114,10 @@ static void do_kdeltkt (int count, char *names[],

ret = krb5_parse_name(context, names[i], &in_creds.server);
if (ret) {
if (!quiet)
if (!quiet) {
fprintf(stderr, "%s: %s while parsing principal name\n",
names[i], error_message(ret));
}
errors++;
continue;
}
Expand All @@ -133,9 +137,7 @@ static void do_kdeltkt (int count, char *names[],
if (ret) {
fprintf(stderr, "%s: %s while retrieving credentials\n",
princ, error_message(ret));

krb5_free_unparsed_name(context, princ);

errors++;
continue;
}
Expand All @@ -147,14 +149,11 @@ static void do_kdeltkt (int count, char *names[],
if (ret) {
fprintf(stderr, "%s: %s while removing credentials\n",
princ, error_message(ret));

krb5_free_cred_contents(context, &out_creds);
krb5_free_unparsed_name(context, princ);

errors++;
continue;
}

krb5_free_unparsed_name(context, princ);
krb5_free_cred_contents(context, &out_creds);
}
Expand Down
77 changes: 35 additions & 42 deletions src/clients/kdestroy/kdestroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ extern int optind;
extern char *optarg;

#ifndef _WIN32
#define GET_PROGNAME(x) (strrchr((x), '/') ? strrchr((x), '/')+1 : (x))
#define GET_PROGNAME(x) (strrchr((x), '/') ? strrchr((x), '/') + 1 : (x))
#else
#define GET_PROGNAME(x) max(max(strrchr((x), '/'), strrchr((x), '\\')) + 1,(x))
#endif

char *progname;


static void usage()
static void
usage()
{
#define KRB_AVAIL_STRING(x) ((x)?"available":"not available")

fprintf(stderr, _("Usage: %s [-A] [-q] [-c cache_name]\n"), progname);
fprintf(stderr, _("\t-A destroy all credential caches in collection\n"));
fprintf(stderr, _("\t-q quiet mode\n"));
Expand All @@ -64,18 +63,18 @@ static void usage()
static void
print_remaining_cc_warning(krb5_context context)
{
krb5_error_code retval;
krb5_error_code ret;
krb5_ccache cache;
krb5_cccol_cursor cursor;

retval = krb5_cccol_cursor_new(context, &cursor);
if (retval) {
com_err(progname, retval, _("while listing credential caches"));
ret = krb5_cccol_cursor_new(context, &cursor);
if (ret) {
com_err(progname, ret, _("while listing credential caches"));
exit(1);
}

retval = krb5_cccol_cursor_next(context, cursor, &cache);
if (retval == 0 && cache != NULL) {
ret = krb5_cccol_cursor_next(context, cursor, &cache);
if (ret == 0 && cache != NULL) {
fprintf(stderr,
_("Other credential caches present, use -A to destroy all\n"));
krb5_cc_close(context, cache);
Expand All @@ -85,20 +84,14 @@ print_remaining_cc_warning(krb5_context context)
}

int
main(argc, argv)
int argc;
char **argv;
main(int argc, char *argv[])
{
krb5_context kcontext;
krb5_error_code retval;
int c;
krb5_context context;
krb5_error_code ret;
krb5_ccache cache = NULL;
krb5_cccol_cursor cursor;
char *cache_name = NULL;
int code = 0;
int errflg = 0;
int quiet = 0;
int all = 0;
int code = 0, errflg = 0, quiet = 0, all = 0, c;

setlocale(LC_ALL, "");
progname = GET_PROGNAME(argv[0]);
Expand Down Expand Up @@ -135,62 +128,61 @@ main(argc, argv)
if (optind != argc)
errflg++;

if (errflg) {
if (errflg)
usage();
}

retval = krb5_init_context(&kcontext);
if (retval) {
com_err(progname, retval, _("while initializing krb5"));
ret = krb5_init_context(&context);
if (ret) {
com_err(progname, ret, _("while initializing krb5"));
exit(1);
}

if (all) {
code = krb5_cccol_cursor_new(kcontext, &cursor);
code = krb5_cccol_cursor_new(context, &cursor);
if (code) {
com_err(progname, code, _("while listing credential caches"));
exit(1);
}
while ((code = krb5_cccol_cursor_next(kcontext, cursor,
&cache)) == 0 && cache != NULL) {
code = krb5_cc_get_full_name(kcontext, cache, &cache_name);
while (krb5_cccol_cursor_next(context, cursor, &cache) == 0 &&
cache != NULL) {
code = krb5_cc_get_full_name(context, cache, &cache_name);
if (code) {
com_err(progname, code, _("composing ccache name"));
exit(1);
}
code = krb5_cc_destroy(kcontext, cache);
code = krb5_cc_destroy(context, cache);
if (code && code != KRB5_FCC_NOFILE) {
com_err(progname, code, _("while destroying cache %s"),
cache_name);
}
krb5_free_string(kcontext, cache_name);
krb5_free_string(context, cache_name);
}
krb5_cccol_cursor_free(kcontext, &cursor);
krb5_free_context(kcontext);
krb5_cccol_cursor_free(context, &cursor);
krb5_free_context(context);
return 0;
}

if (cache_name) {
code = krb5_cc_resolve (kcontext, cache_name, &cache);
if (cache_name != NULL) {
code = krb5_cc_resolve(context, cache_name, &cache);
if (code != 0) {
com_err(progname, code, _("while resolving %s"), cache_name);
exit(1);
}
} else {
code = krb5_cc_default(kcontext, &cache);
code = krb5_cc_default(context, &cache);
if (code) {
com_err(progname, code, _("while getting default ccache"));
exit(1);
}
}

code = krb5_cc_destroy (kcontext, cache);
code = krb5_cc_destroy(context, cache);
if (code != 0) {
com_err (progname, code, _("while destroying cache"));
com_err(progname, code, _("while destroying cache"));
if (code != KRB5_FCC_NOFILE) {
if (quiet)
if (quiet) {
fprintf(stderr, _("Ticket cache NOT destroyed!\n"));
else {
} else {
fprintf(stderr, _("Ticket cache %cNOT%c destroyed!\n"),
BELL_CHAR, BELL_CHAR);
}
Expand All @@ -199,8 +191,9 @@ main(argc, argv)
}

if (!quiet && !errflg)
print_remaining_cc_warning(kcontext);
print_remaining_cc_warning(context);

krb5_free_context(context);

krb5_free_context(kcontext);
return errflg;
}
Loading

0 comments on commit b3df4f4

Please sign in to comment.