Beispiel #1
0
static int
name_convert(krb5_context context, const char *name, const char *realm, 
	     const char **out)
{
    const krb5_config_binding *l;
    l = krb5_config_get_list (context,
			      NULL,
			      "realms",
			      realm,
			      "v4_name_convert",
			      "host",
			      NULL);
    if(l && check_list(l, name, out))
	return KRB5_NT_SRV_HST;
    l = krb5_config_get_list (context,
			      NULL,
			      "libdefaults",
			      "v4_name_convert",
			      "host",
			      NULL);
    if(l && check_list(l, name, out))
	return KRB5_NT_SRV_HST;
    l = krb5_config_get_list (context,
			      NULL,
			      "realms",
			      realm,
			      "v4_name_convert",
			      "plain",
			      NULL);
    if(l && check_list(l, name, out))
	return KRB5_NT_UNKNOWN;
    l = krb5_config_get_list (context,
			      NULL,
			      "libdefaults",
			      "v4_name_convert",
			      "host",
			      NULL);
    if(l && check_list(l, name, out))
	return KRB5_NT_UNKNOWN;
    
    /* didn't find it in config file, try built-in list */
    {
	struct v4_name_convert *q;
	for(q = default_v4_name_convert; q->from; q++) {
	    if(strcmp(name, q->to) == 0) {
		*out = q->from;
		return KRB5_NT_SRV_HST;
	    }
	}
    }
    return -1;
}
Beispiel #2
0
int
hdb_get_dbinfo(krb5_context context, struct hdb_dbinfo **dbp)
{
    const krb5_config_binding *db_binding;
    struct hdb_dbinfo *di, **dt, *databases;
    const char *default_dbname = HDB_DEFAULT_DB;
    const char *default_mkey = HDB_DB_DIR "/m-key";
    const char *default_acl = HDB_DB_DIR "/kadmind.acl";
    const char *p;
    int ret;

    *dbp = NULL;
    dt = NULL;
    databases = NULL;

    db_binding = krb5_config_get_list(context, NULL,
				      "kdc",
				      "database",
				      NULL);
    if (db_binding) {

	ret = get_dbinfo(context, db_binding, "default", &di);
	if (ret == 0 && di) {
	    databases = di;
	    dt = &di->next;
	}

	for ( ; db_binding != NULL; db_binding = db_binding->next) {

	    if (db_binding->type != krb5_config_list)
		continue;

	    ret = get_dbinfo(context, db_binding->u.list,
			     db_binding->name, &di);
	    if (ret)
		krb5_err(context, 1, ret, "failed getting realm");

	    if (di == NULL)
		continue;

	    if (dt)
		*dt = di;
	    else
		databases = di;
	    dt = &di->next;

	}
    }

    if(databases == NULL) {
	/* if there are none specified, create one and use defaults */
	di = calloc(1, sizeof(*di));
	databases = di;
	di->label = strdup("default");
    }

    for(di = databases; di; di = di->next) {
	if(di->dbname == NULL) {
	    di->dbname = strdup(default_dbname);
	    if (di->mkey_file == NULL)
		di->mkey_file = strdup(default_mkey);
	}
	if(di->mkey_file == NULL) {
	    p = strrchr(di->dbname, '.');
	    if(p == NULL || strchr(p, '/') != NULL)
		/* final pathname component does not contain a . */
		asprintf(&di->mkey_file, "%s.mkey", di->dbname);
	    else
		/* the filename is something.else, replace .else with
                   .mkey */
		asprintf(&di->mkey_file, "%.*s.mkey",
			 (int)(p - di->dbname), di->dbname);
	}
	if(di->acl_file == NULL)
	    di->acl_file = strdup(default_acl);
    }
    *dbp = databases;
    return 0;
}