Blame src/kadmin/cli/ss_wrapper.c

Packit fd8b60
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
Packit fd8b60
/*
Packit fd8b60
 * Copyright 1994 by the Massachusetts Institute of Technology.
Packit fd8b60
 * All Rights Reserved.
Packit fd8b60
 *
Packit fd8b60
 * Export of this software from the United States of America may
Packit fd8b60
 *   require a specific license from the United States Government.
Packit fd8b60
 *   It is the responsibility of any person or organization contemplating
Packit fd8b60
 *   export to obtain such a license before exporting.
Packit fd8b60
 *
Packit fd8b60
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
Packit fd8b60
 * distribute this software and its documentation for any purpose and
Packit fd8b60
 * without fee is hereby granted, provided that the above copyright
Packit fd8b60
 * notice appear in all copies and that both that copyright notice and
Packit fd8b60
 * this permission notice appear in supporting documentation, and that
Packit fd8b60
 * the name of M.I.T. not be used in advertising or publicity pertaining
Packit fd8b60
 * to distribution of the software without specific, written prior
Packit fd8b60
 * permission.  Furthermore if you modify this software you must label
Packit fd8b60
 * your software as modified software and not distribute it in such a
Packit fd8b60
 * fashion that it might be confused with the original M.I.T. software.
Packit fd8b60
 * M.I.T. makes no representations about the suitability of
Packit fd8b60
 * this software for any purpose.  It is provided "as is" without express
Packit fd8b60
 * or implied warranty.
Packit fd8b60
 */
Packit fd8b60
Packit fd8b60
#include <k5-platform.h>
Packit fd8b60
#include <krb5.h>
Packit fd8b60
#include <locale.h>
Packit fd8b60
#include <ss/ss.h>
Packit fd8b60
#include "kadmin.h"
Packit fd8b60
Packit fd8b60
#ifdef NEED_SS_EXECUTE_COMMAND_PROTO
Packit fd8b60
int ss_execute_command(int, char **);
Packit fd8b60
#endif
Packit fd8b60
Packit fd8b60
extern ss_request_table kadmin_cmds;
Packit fd8b60
extern int exit_status;
Packit fd8b60
extern char *whoami;
Packit fd8b60
Packit fd8b60
int
Packit fd8b60
main(int argc, char *argv[])
Packit fd8b60
{
Packit fd8b60
    char *request, **args;
Packit fd8b60
    krb5_error_code retval;
Packit fd8b60
    int sci_idx, code = 0;
Packit fd8b60
Packit fd8b60
    setlocale(LC_ALL, "");
Packit fd8b60
    whoami = ((whoami = strrchr(argv[0], '/')) ? whoami+1 : argv[0]);
Packit fd8b60
Packit fd8b60
    kadmin_startup(argc, argv, &request, &args);
Packit fd8b60
    sci_idx = ss_create_invocation(whoami, "5.0", NULL, &kadmin_cmds, &retval);
Packit fd8b60
    if (retval) {
Packit fd8b60
        ss_perror(sci_idx, retval, _("creating invocation"));
Packit fd8b60
        exit(1);
Packit fd8b60
    }
Packit fd8b60
Packit fd8b60
    if (*args != NULL) {
Packit fd8b60
        /* Execute post-option arguments as a single script-mode command. */
Packit fd8b60
        code = ss_execute_command(sci_idx, args);
Packit fd8b60
        if (code) {
Packit fd8b60
            ss_perror(sci_idx, code, *args);
Packit fd8b60
            exit_status = 1;
Packit fd8b60
        }
Packit fd8b60
    } else if (request != NULL) {
Packit fd8b60
        /* Execute the -q option as a single interactive command. */
Packit fd8b60
        code = ss_execute_line(sci_idx, request);
Packit fd8b60
        if (code != 0) {
Packit fd8b60
            ss_perror(sci_idx, code, request);
Packit fd8b60
            exit_status = 1;
Packit fd8b60
        }
Packit fd8b60
    } else {
Packit fd8b60
        /* Prompt for commands. */
Packit fd8b60
        (void)ss_listen(sci_idx);
Packit fd8b60
    }
Packit fd8b60
Packit fd8b60
    return quit() ? 1 : exit_status;
Packit fd8b60
}