Exemplo n.º 1
0
/* vcd.user.remove(string username) */
xmlrpc_value *m_vcd_user_remove(xmlrpc_env *env, xmlrpc_value *p, void *c)
{
	LOG_TRACEME

	xmlrpc_value *params;
	char *user;
	int rc, uid = 0;

	params = method_init(env, p, c, VCD_CAP_AUTH, 0);
	method_return_if_fault(env);

	xmlrpc_decompose_value(env, params,
			"{s:s,*}",
			"username", &user);
	method_return_if_fault(env);

	if (!(uid = auth_getuid(user)))
		method_return_fault(env, MENOUSER);

	rc = vxdb_exec(
			"BEGIN TRANSACTION;"
			"DELETE FROM xid_uid_map WHERE uid = %d;"
			"DELETE FROM user_caps WHERE uid = %d;"
			"DELETE FROM user WHERE uid = %d;"
			"COMMIT TRANSACTION;",
		uid, uid, uid);

	if (rc != VXDB_OK)
		method_return_vxdb_fault(env);

	return xmlrpc_nil_new(env);
}
Exemplo n.º 2
0
/* vcd.status() */
xmlrpc_value *m_vcd_status(xmlrpc_env *env, xmlrpc_value *p, void *c)
{
	LOG_TRACEME

	xmlrpc_value *response = NULL;
	int rc;

	method_init(env, p, c, VCD_CAP_INFO, 0);
	method_return_if_fault(env);

	rc = vxdb_prepare(&dbr,
			"SELECT uptime, requests, flogins, nomethod FROM vcd "
			"ORDER BY uptime DESC LIMIT 1");

	if (rc != VXDB_OK)
		method_return_vxdb_fault(env);

	rc = vxdb_step(dbr);

	if (rc == VXDB_ROW)
		response = xmlrpc_build_value(env, "{s:i,s:i,s:i,s:i}",
				"uptime",   time(NULL) - vxdb_column_int(dbr, 0),
				"requests", vxdb_column_int(dbr, 1),
				"flogins",  vxdb_column_int(dbr, 2),
				"nomethod", vxdb_column_int(dbr, 3));
	else if (rc == VXDB_DONE)
		response = xmlrpc_nil_new(env);
	else
		method_set_vxdb_fault(env);

	vxdb_finalize(dbr);

	return response;
}
Exemplo n.º 3
0
/* vg.remove(string group, string name) */
xmlrpc_value *m_vg_remove(xmlrpc_env *env, xmlrpc_value *p, void *c)
{
	LOG_TRACEME

	xmlrpc_value *params;
	char *group, *name;
	int rc, gid = 0;
	xid_t xid;

	params = method_init(env, p, c, VCD_CAP_AUTH, 0);
	method_return_if_fault(env);

	xmlrpc_decompose_value(env, params,
			"{s:s,s:s,*}",
			"group", &group,
			"name",  &name);
	method_return_if_fault(env);

	if (!validate_group(group))
		method_return_faultf(env, MEINVAL,
				"invalid group value: %s", group);

	if (str_equal(group, "all"))
		method_return_faultf(env, MEINVAL,
				"cannot remove reserved group '%s'", group);

	if (!(gid = vxdb_getgid(group)))
		method_return_fault(env, MENOVG);

	if (!str_isempty(name)) {
		if (!validate_name(name))
			method_return_faultf(env, MEINVAL,
					"invalid name value: %s", name);

		if (!(xid = vxdb_getxid(name)))
			method_return_fault(env, MENOVPS);

		rc = vxdb_exec(
				"DELETE FROM xid_gid_map WHERE xid = %d AND gid = %d",
				xid, gid);
	}

	else {
		rc = vxdb_exec(
				"BEGIN EXCLUSIVE TRANSACTION;"
				"DELETE FROM xid_gid_map WHERE gid = %d;"
				"DELETE FROM groups WHERE gid = %d;"
				"COMMIT TRANSACTION;",
				gid, gid);
	}

	if (rc != VXDB_OK)
		method_return_vxdb_fault(env);

	return xmlrpc_nil_new(env);
}
Exemplo n.º 4
0
/* vxdb.owner.remove(string name[, string username]) */
xmlrpc_value *m_vxdb_owner_remove(xmlrpc_env *env, xmlrpc_value *p, void *c)
{
	LOG_TRACEME

	xmlrpc_value *params;
	char *name, *user;
	int rc, uid = 0;
	xid_t xid;

	params = method_init(env, p, c, VCD_CAP_AUTH, 0);
	method_return_if_fault(env);

	xmlrpc_decompose_value(env, params,
			"{s:s,s:s,*}",
			"name",     &name,
			"username", &user);
	method_return_if_fault(env);

	method_empty_params(1, &user);

	if (!(xid = vxdb_getxid(name)))
		method_return_fault(env, MENOVPS);

	if (user && !(uid = auth_getuid(user)))
		method_return_faultf(env, MENOUSER,
				"user does not exist: %s", user);

	if (uid)
		rc = vxdb_exec(
				"DELETE FROM xid_uid_map WHERE xid = %d AND uid = %d",
				xid, uid);

	else
		rc = vxdb_exec(
				"DELETE FROM xid_uid_map WHERE xid = %d",
				xid);

	if (rc != VXDB_OK)
		method_return_vxdb_fault(env);

	return xmlrpc_nil_new(env);
}
Exemplo n.º 5
0
static void
test_value_nil(void) {

    xmlrpc_value * v;
    xmlrpc_env env;

    xmlrpc_env_init(&env);

    v = xmlrpc_nil_new(&env);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_NIL == xmlrpc_value_type(v));
    xmlrpc_DECREF(v);

    v = xmlrpc_build_value(&env, "n");
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_NIL == xmlrpc_value_type(v));
    xmlrpc_decompose_value(&env, v, "n");
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);

    xmlrpc_env_clean(&env);
}
Exemplo n.º 6
0
        cWrapper() {
            env_wrap env;

            this->valueP = xmlrpc_nil_new(&env.env_c);
            throwIfError(env);
        }