static kadm5_ret_t
find_db_spec(kadm5_server_context *ctx)
{
    krb5_context context = ctx->context;
    struct hdb_dbinfo *info, *d;
    krb5_error_code ret;

    if (ctx->config.realm) {
	/* fetch the databases */
	ret = hdb_get_dbinfo(context, &info);
	if (ret)
	    return ret;

	d = NULL;
	while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {
	    const char *p = hdb_dbinfo_get_realm(context, d);

	    /* match default (realm-less) */
	    if(p != NULL && strcmp(ctx->config.realm, p) != 0)
		continue;

	    p = hdb_dbinfo_get_dbname(context, d);
	    if (p)
		ctx->config.dbname = strdup(p);

	    p = hdb_dbinfo_get_acl_file(context, d);
	    if (p)
		ctx->config.acl_file = strdup(p);

	    p = hdb_dbinfo_get_mkey_file(context, d);
	    if (p)
		ctx->config.stash_file = strdup(p);

	    p = hdb_dbinfo_get_log_file(context, d);
	    if (p)
		ctx->log_context.log_file = strdup(p);
	    break;
	}
	hdb_free_dbinfo(context, &info);
    }

    /* If any of the values was unset, pick up the default value */

    if (ctx->config.dbname == NULL)
	ctx->config.dbname = strdup(hdb_default_db(context));
    if (ctx->config.acl_file == NULL)
	asprintf(&ctx->config.acl_file, "%s/kadmind.acl", hdb_db_dir(context));
    if (ctx->config.stash_file == NULL)
	asprintf(&ctx->config.stash_file, "%s/m-key", hdb_db_dir(context));
    if (ctx->log_context.log_file == NULL)
	asprintf(&ctx->log_context.log_file, "%s/log", hdb_db_dir(context));

#ifndef NO_UNIX_SOCKETS
    set_socket_name(context, &ctx->log_context.socket_name);
#else
    set_socket_info(context, &ctx->log_context.socket_info);
#endif

    return 0;
}
Esempio n. 2
0
static int server_create_socket(const char *name) {
	if (!set_socket_name(&sockaddr, name))
		return -1;
	int fd = socket(AF_UNIX, SOCK_STREAM, 0);
	if (fd == -1)
		return -1;
	socklen_t socklen = offsetof(struct sockaddr_un, sun_path) + strlen(sockaddr.sun_path) + 1;
	mode_t mask = umask(S_IXUSR|S_IRWXG|S_IRWXO);
	int r = bind(fd, (struct sockaddr*)&sockaddr, socklen);
	umask(mask);

	if (r == -1) {
		close(fd);
		return -1;
	}

	if (listen(fd, 5) == -1) {
		unlink(sockaddr.sun_path);
		close(fd);
		return -1;
	}

	return fd;
}