Пример #1
0
int
main(int argc, char **argv)
{
    int argcc,port,i;
    int ret=0;

    argcc = argc;
    port = client_setup(&context, &argcc, argv);

    if (remote_name == NULL) {
	remote_name = get_default_username ();
	if (remote_name == NULL)
	    errx (1, "who are you?");
    }

    for (i = argcc;i < argc; i++) {
	char message[128];
	ret = doit (argv[i], port, service, message, sizeof(message));
	if(ret == 0)
	    warnx ("%s: ok", argv[i]);
	else
	    warnx ("%s: failed: %s", argv[i], message);
    }
    return(ret);
}
Пример #2
0
static void
parse_pobox (char *a0, const char **host, const char **user)
{
    const char *h, *u;
    char *p;
    int po = 0;

    if (a0 == NULL) {

	*user = getenv ("USERNAME");
	if (*user == NULL) {
	    struct passwd *pwd = getpwuid (getuid ());

	    if (pwd == NULL)
		errx (1, "Who are you?");
	    *user = estrdup (pwd->pw_name);
	}
	*host = get_pobox (user);
	return;
    }

    /* if the specification starts with po:, remember this information */
    if(strncmp(a0, "po:", 3) == 0) {
	a0 += 3;
	po++;
    }
    /* if there is an `@', the hostname is after it, otherwise at the
       beginning of the string */
    p = strchr(a0, '@');
    if(p != NULL) {
	*p++ = '\0';
	h = p;
    } else {
	h = a0;
    }
    /* if there is a `:', the username comes before it, otherwise at
       the beginning of the string */
    p = strchr(a0, ':');
    if(p != NULL) {
	*p++ = '\0';
	u = p;
    } else {
	u = a0;
    }
    if(h == u) {
	/* some inconsistent compatibility with various mailers */
	if(po) {
	    h = get_pobox (&u);
	} else {
	    u = get_default_username ();
	    if (u == NULL)
		errx (1, "Who are you?");
	}
    }
    *host = h;
    *user = u;
}
Пример #3
0
krb5_error_code
_kadm5_c_get_cred_cache(krb5_context context,
			const char *client_name,
			const char *server_name,
			const char *password,
			krb5_prompter_fct prompter,
			const char *keytab,
			krb5_ccache ccache,
			krb5_ccache *ret_cache)
{
    krb5_error_code ret;
    krb5_ccache id = NULL;
    krb5_principal default_client = NULL, client = NULL;

    /* treat empty password as NULL */
    if(password && *password == '\0')
	password = NULL;
    if(server_name == NULL)
	server_name = KADM5_ADMIN_SERVICE;

    if(client_name != NULL) {
	ret = krb5_parse_name(context, client_name, &client);
	if(ret)
	    return ret;
    }

    if(ccache != NULL) {
	id = ccache;
	ret = krb5_cc_get_principal(context, id, &client);
	if(ret)
	    return ret;
    } else {
	/* get principal from default cache, ok if this doesn't work */

	ret = get_cache_principal(context, &id, &default_client);
	if (ret) {
	    /*
	     * No client was specified by the caller and we cannot
	     * determine the client from a credentials cache.
	     */
	    const char *user;

	    user = get_default_username ();

	    if(user == NULL) {
		krb5_set_error_message(context, KADM5_FAILURE, "Unable to find local user name");
		return KADM5_FAILURE;
	    }
	    ret = krb5_make_principal(context, &default_client,
				      NULL, user, "admin", NULL);
	    if(ret)
		return ret;
	}
    }


    /*
     * No client was specified by the caller, but we have a client
     * from the default credentials cache.
     */
    if (client == NULL && default_client != NULL)
	client = default_client;


    if(id && client && (default_client == NULL ||
	      krb5_principal_compare(context, client, default_client) != 0)) {
	ret = get_kadm_ticket(context, id, client, server_name);
	if(ret == 0) {
	    *ret_cache = id;
	    krb5_free_principal(context, default_client);
	    if (default_client != client)
		krb5_free_principal(context, client);
	    return 0;
	}
	if(ccache != NULL)
	    /* couldn't get ticket from cache */
	    return -1;
    }
    /* get creds via AS request */
    if(id && (id != ccache))
	krb5_cc_close(context, id);
    if (client != default_client)
	krb5_free_principal(context, default_client);

    ret = get_new_cache(context, client, password, prompter, keytab,
			server_name, ret_cache);
    krb5_free_principal(context, client);
    return ret;
}
Пример #4
0
int
main(int argc, char **argv)
{
    int port	= 0;
    int optidx	= 0;
    int ret	= 1;
    char *host	= NULL;

    setprogname (argv[0]);

    if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv,
		&optidx))
	usage (1);

    if (help_flag)
	usage (0);

    if (version_flag) {
	print_version (NULL);
	return 0;
    }

    if (optidx != argc - 1)
	usage (1);

    host = argv[optidx];

    if (port_str) {
	struct servent *s = roken_getservbyname (port_str, "tcp");

	if (s)
	    port = s->s_port;
	else {
	    char *ptr;

	    port = strtol (port_str, &ptr, 10);
	    if (port == 0 && ptr == port_str)
		errx (1, "Bad port `%s'", port_str);
	    port = htons(port);
	}
    }

    if (user == NULL) {
	user = get_default_username ();
	if (user == NULL)
	    errx (1, "who are you?");
    }

    if (!passive_flag)
	passive_flag = check_for_passive (getenv("DISPLAY"));

#if defined(HAVE_KERNEL_ENABLE_DEBUG)
    if (krb_debug_flag)
	krb_enable_debug ();
#endif

#ifdef KRB5
    if (ret && use_v5) {
	if (port == 0)
	    port = krb5_getportbyname(NULL, "kx", "tcp", KX_PORT);
	ret = doit_v5 (host, port, user,
		       passive_flag, debug_flag, keepalive_flag, tcp_flag);
    }
#endif
    return ret;
}
Пример #5
0
void controller::start_connection(const std::string& hostname) {
    start_connection(hostname, get_default_nick(), get_default_username(),
                     get_default_fullname(), get_default_port());
}
Пример #6
0
krb5_error_code
_kadm5_c_get_cred_cache(krb5_context context,
			const char *client_name,
			const char *server_name,
			const char *password,
			krb5_prompter_fct prompter,
			const char *keytab,
			krb5_ccache ccache,
			krb5_ccache *ret_cache)
{
    krb5_error_code ret;
    krb5_ccache id = NULL;
    krb5_principal default_client = NULL, client = NULL;
    
    /* treat empty password as NULL */
    if(password && *password == '\0')
	password = NULL;
    if(server_name == NULL)
	server_name = KADM5_ADMIN_SERVICE;
    
    if(client_name != NULL) {
	ret = krb5_parse_name(context, client_name, &client);
	if(ret) 
	    return ret;
    }

    if(password != NULL || prompter != NULL) {
	/* get principal from default cache, ok if this doesn't work */
	ret = krb5_cc_default(context, &id);
	if(ret == 0) {
	    ret = krb5_cc_get_principal(context, id, &default_client);
	    if(ret) {
		krb5_cc_close(context, id);
		id = NULL;
	    } else {
		const char *name, *inst;
		krb5_principal tmp;
		name = krb5_principal_get_comp_string(context, 
						      default_client, 0);
		inst = krb5_principal_get_comp_string(context, 
						      default_client, 1);
		if(inst == NULL || strcmp(inst, "admin") != 0) {
		    ret = krb5_make_principal(context, &tmp, NULL, 
					      name, "admin", NULL);
		    if(ret != 0) {
			krb5_free_principal(context, default_client);
			if (client)
			    krb5_free_principal(context, client);
			krb5_cc_close(context, id);
			return ret;
		    }
		    krb5_free_principal(context, default_client);
		    default_client = tmp;
		    krb5_cc_close(context, id);
		    id = NULL;
		}
	    }
	}

	if (client != NULL) {
	    /* A client was specified by the caller. */
	    if (default_client != NULL) {
		krb5_free_principal(context, default_client);
		default_client = NULL;
	    }
	}
	else if (default_client != NULL)
	    /* No client was specified by the caller, but we have a
	     * client from the default credentials cache.
	     */
	    client = default_client;
	else {
	    /* No client was specified by the caller and we cannot determine
	     * the client from a credentials cache.
	     */
	    const char *user;

	    user = get_default_username ();

	    if(user == NULL)
		return KADM5_FAILURE;
	    ret = krb5_make_principal(context, &client, 
				      NULL, user, "admin", NULL);
	    if(ret)
		return ret;
	    if (id != NULL) {
		krb5_cc_close(context, id);
		id = NULL;
	    }
	}
    } else if(ccache != NULL) {
	id = ccache;
	ret = krb5_cc_get_principal(context, id, &client);
	if(ret)
	    return ret;
    }

    
    if(id && (default_client == NULL || 
	      krb5_principal_compare(context, client, default_client))) {
	ret = get_kadm_ticket(context, id, client, server_name);
	if(ret == 0) {
	    *ret_cache = id;
	    krb5_free_principal(context, default_client);
	    if (default_client != client)
		krb5_free_principal(context, client);
	    return 0;
	}
	if(ccache != NULL)
	    /* couldn't get ticket from cache */
	    return -1;
    }
    /* get creds via AS request */
    if(id && (id != ccache))
	krb5_cc_close(context, id);
    if (client != default_client)
	krb5_free_principal(context, default_client);

    ret = get_new_cache(context, client, password, prompter, keytab, 
			server_name, ret_cache);
    krb5_free_principal(context, client);
    return ret;
}