Esempio n. 1
0
static int
check_acl(int node, struct Creds *cred)
{
    gid_t gids[64];
    int nr_gids = 64;
    struct passwd *pw;
    struct acl_class *ac;
    struct acl_group *ag;
    void *acptr = ∾
    int level;
    int i, j;

    model_acl_get(model_parent(node), acptr, &level);
    if (!ac) return 0;

    pw = getpwuid(cred->uid);
    if (!pw) return 0;
    if (getgrouplist(pw->pw_name, cred->gid, &gids[0], &nr_gids) < 0) {
        nr_gids = 63;
    }

    for (i = 0; i < nr_gids; i++) {
        for (j = 0; j < ac->nr_groups; j++) {
            ag = &ac->group[j];
            if (gids[i] == ag->gid) {
                if (ag->level <= level)
                    return 1;
                else
                    break;
            }
        }
    }

    return 0;
}
Esempio n. 2
0
File: job.c Progetto: Tayyib/uludag
static int
do_execute(int node, const char *app)
{
	char *code;
	char *res;
	size_t code_size;
	size_t res_size;
	int e;

	log_debug(LOG_JOB, "Execute(%s,%s)\n", model_get_path(node), app);

	bk_app = (char *) app;

	csl_setup();

	if (0 != db_get_code(model_parent(node), app, &code, &code_size)) return -1;
	e = csl_execute(code, code_size, model_get_method(node), &res, &res_size);
	if (e) {
		send_result(CMD_ERROR, "err", 3);
	} else {
		send_result(CMD_RESULT, res, res_size);
	}
	free(res);

	csl_cleanup();

	return e;
}
Esempio n. 3
0
File: job.c Progetto: Tayyib/uludag
static int
do_call(int node)
{
	char *apps;

	log_debug(LOG_JOB, "Call(%s)\n", model_get_path(node));

	if (db_get_apps(model_parent(node), &apps) != 0) {
		send_result(CMD_ERROR, "no app", 6);
		exit(1);
	}

	if (strchr(apps, '/') == NULL) {
		// there is only one script
		do_execute(node, apps);
	} else {
		// multiple scripts, run concurrently
		char *t, *s;
		struct ProcChild *p;
		int cmd;
		int cnt = 0;
		size_t size;

		// FIXME: package count
		send_result(CMD_RESULT_START, NULL, 0);
		for (t = apps; t; t = s) {
			s = strchr(t, '/');
			if (s) {
				*s = '\0';
				++s;
			}
			bk_node = node;
			bk_app = t;
			p = proc_fork(exec_proc, "SubJob");
			if (p) {
				++cnt;
			} else {
				send_result(CMD_ERROR, "fork failed", 11);
			}
		}
		while(1) {
			struct ipc_data *ipc;
			proc_listen(&p, &cmd, &size, -1);
			if (cmd == CMD_FINISH) {
				--cnt;
				if (!cnt) break;
			} else {
				proc_recv(p, &ipc, size);
				proc_send(TO_PARENT, cmd, ipc, size);
			}
		}
		send_result(CMD_RESULT_END, NULL, 0);
	}

	return 0;
}
Esempio n. 4
0
File: data.c Progetto: Tayyib/uludag
static char *
make_profile_key(int method, const char *app, const char *inst_key, const char *inst_value)
{
	size_t len;
	const char *node;
	char *inst_sep = "";
	char *key;

// key format: Node / [App] / [instance = [ value ] ]

	if (inst_key)
		// instances belong to the class
		node = model_get_path(model_parent(method));
	else
		// globals belong to the method
		node = model_get_path(method);

	len = strlen(node) + 3;

	if (app)
		len += strlen(app);
	else
		app = "";

	if (inst_key) {
		if (!inst_value) inst_value = "";
		len += strlen(inst_key) + 1 + strlen(inst_value);
		inst_sep = "=";
	} else {
		inst_key = "";
		inst_value = "";
	}

	key = malloc(len);
	if (!key) return NULL;

	snprintf(key, len, "%s/%s/%s%s%s", node, app, inst_key, inst_sep, inst_value);

	return key;
}
Esempio n. 5
0
File: acl.c Progetto: Tayyib/uludag
static int
check_acl(int node, struct Creds *cred)
{
	gid_t gids[64];
	int nr_gids = 64;
	struct passwd *pw;
	struct acl_node *n;
	int i;

	node = model_parent(node);

	n = get_node(acl_uids.admins, cred->uid);
	if (n) {
		for (i = 0; i < n->nr_nodes; i++) {
			if (n->node[i] == node)
				return 1;
		}
	}

	pw = getpwuid(cred->uid);
	if (!pw) return 0;
	if (getgrouplist(pw->pw_name, cred->gid, &gids[0], &nr_gids) < 0) {
		nr_gids = 63;
	}

	for (i = 0; i < nr_gids; i++) {
		n = get_node(acl_gids.admins, gids[i]);
		if (n) {
			for (i = 0; i < n->nr_nodes; i++) {
				if (n->node[i] == node)
					return 1;
			}
		}
	}

	return 0;
}
Esempio n. 6
0
File: job.c Progetto: Tayyib/uludag
static int
do_call(int node, struct pack *pak)
{
	struct pack *p = NULL;
	char *apps;
	int ok = 0;

	log_debug(LOG_JOB, "Call(%s)\n", model_get_path(node));

	if (model_flags(node) & P_GLOBAL) {
		p = pack_dup(pak);
	}

	if (db_get_apps(model_parent(node), &apps) != 0) {
		send_result(CMD_NONE, "noapp", 5);
		// FIXME: ok diyecek betik yoksa profile kayıt etmeli mi acaba
		exit(1);
	}

	if (strchr(apps, '/') == NULL) {
		// there is only one script
		if (0 == do_execute(node, apps, pak))
			ok = 1;
	} else {
		// multiple scripts, run concurrently
		char *t, *s;
		struct ProcChild *p;
		int cmd;
		int cnt = 0;
		size_t size;

		// FIXME: package count
		send_result(CMD_RESULT_START, NULL, 0);
		for (t = apps; t; t = s) {
			s = strchr(t, '/');
			if (s) {
				*s = '\0';
				++s;
			}
			bk_node = node;
			bk_app = t;
			bk_pak = pak;
			p = proc_fork(exec_proc, "ComarSubJob");
			if (p) {
				++cnt;
			} else {
				send_result(CMD_ERROR, "fork failed", 11);
			}
		}
		while(1) {
			struct ipc_struct ipc;
			struct pack *pak;
			pak = pack_new(128);
			proc_listen(&p, &cmd, &size, -1);
			if (cmd == CMD_FINISH) {
				--cnt;
				if (!cnt) break;
			} else {
				if (cmd == CMD_RESULT) ok++;
				proc_get(p, &ipc, pak, size);
				proc_put(TO_PARENT, cmd, &ipc, pak);
			}
		}
		send_result(CMD_RESULT_END, NULL, 0);
	}

    if ((model_flags(node) & P_GLOBAL) && ok) {
		db_put_profile(node, NULL, p);
		pack_delete(p);
	}

	return 0;
}
Esempio n. 7
0
File: job.c Progetto: Tayyib/uludag
static int
do_execute(int node, const char *app, struct pack *pak)
{
	struct timeval start, end;
	unsigned long msec;
	struct pack *p = NULL;
	char *code;
	char *res;
	size_t code_size;
	size_t res_size;
	int e;

	log_debug(LOG_JOB, "Execute(%s,%s)\n", model_get_path(node), app);

	bk_app = strdup(app);
	bk_node = node;

	if (model_flags(node) & P_PACKAGE) {
		p = pack_dup(pak);
	}

	csl_setup();

	if (0 != db_get_code(model_parent(node), app, &code, &code_size)) {
		send_result(CMD_NONE, "noapp", 5);
		return -1;
	}

	gettimeofday(&start, NULL);
	e = csl_execute(code, code_size, model_get_method(node), pak, &res, &res_size);
	gettimeofday(&end, NULL);
	if (e) {
		if (e == CSL_NOFUNC)
			send_result(CMD_NONE, "nomethod", 8);
		else
			send_result(CMD_ERROR, "err", 3);
	} else {
		send_result(CMD_RESULT, res, res_size);
		free(res);
	}

	msec = time_diff(&start, &end);
	if (msec > 60*1000) {
		log_info("Script %s took %d seconds for %s call.\n", bk_app, msec / 1000, model_get_path(node));
	} else {
		log_debug(LOG_PERF, "Script %s took %d miliseconds for %s call.\n", bk_app, msec, model_get_path(node));
	}

	if (model_flags(node) & P_PACKAGE) {
		if (0 == e) {
			if (model_flags(node) & P_DELETE)
				db_del_profile(node, bk_app, p);
			else
				db_put_profile(node, bk_app, p);
		}
		pack_delete(p);
	}

	csl_cleanup();

	return e;
}