Kaydet (Commit) a4e82db9 authored tarafından S.Çağlar Onur's avatar S.Çağlar Onur

merged from staj-projeleri

üst 0afdff44
......@@ -37,12 +37,11 @@ static unsigned int acl_nr_allowed_gids;
static int
count_groups(iks *tag, int class_no)
{
/*!
Returns the number of group tags in child tags of 'tag'
It also counts group tags under class tag ( class permissions )
@return Returns number of groups
*/
/*!
Returns the number of group tags in child tags of 'tag'
It also counts group tags under class tag ( class permissions )
@return Returns number of groups
*/
iks *x;
unsigned int nr = 0;
// global permissions
......@@ -63,11 +62,10 @@ count_groups(iks *tag, int class_no)
static void
add_allowed(gid_t gid)
{
/*!
This function allocates memory for allowed group id's. @see acl_allowed_gids
Every group is added once
*/
/*!
This function allocates memory for allowed group id's. @see acl_allowed_gids
Every group is added once
*/
static unsigned int max_allowed = 0;
unsigned int i;
......@@ -94,12 +92,11 @@ add_allowed(gid_t gid)
static void
add_group(iks *tag, int level, struct acl_class *ac)
{
/*!
Scans the 'tag's 'name' attribute, and searches the result in groups database (unix groups db)
When found, numerical group id and level is set to current group structure
\param ac is the allocated memory for acl_group structure \param level is permissions level
*/
/*!
Scans the 'tag's 'name' attribute, and searches the result in groups database (unix groups db)
When found, numerical group id and level is set to current group structure
\param ac is the allocated memory for acl_group structure \param level is permissions level
*/
struct acl_group *ag;
char *name;
struct group *grp;
......@@ -122,12 +119,11 @@ add_group(iks *tag, int level, struct acl_class *ac)
static void
add_groups(iks *tag, int class_no, int level, struct acl_class *ac)
{
· /*!
· Searches 'tag' in 'group' and 'class' tags, calls add_group function with found tags
· level and acl_class is passed to add_group
· \sa add_group
· */
/*!
Searches 'tag' in 'group' and 'class' tags, calls add_group function with found tags
level and acl_class is passed to add_group
\sa add_group
*/
iks *x;
// global permissions
for (x = iks_find(tag, "group"); x; x = iks_next_tag(x)) {
......@@ -146,12 +142,11 @@ add_groups(iks *tag, int class_no, int level, struct acl_class *ac)
static void
set_class(iks *model, int class_no)
{
· /*!
· Allocates memory for all found 'group's in 'model' @see count_groups()
· Then add_groups is called and acl_class is put in node table
· \sa add_groups
· */
/*!
Allocates memory for all found 'group's in 'model' @see count_groups()
Then add_groups is called and acl_class is put in node table
\sa add_groups
*/
struct acl_class *ac;
int nr_groups = 0;
......@@ -174,11 +169,10 @@ set_class(iks *model, int class_no)
void
acl_init(void)
{
· /*!
· Loads /etc/comar/security-policy.xml file
· For all classes in model.xml file, look in security-policy if theres a match
· */
/*!
Loads /etc/comar/security-policy.xml file
For all classes in model.xml file look in security-policy if theres a match
*/
iks *policy;
iks *model;
int class_no;
......@@ -211,11 +205,10 @@ acl_init(void)
static int
check_acl(int node, struct Creds *cred)
{
· /*!
· Checks if cred->uid user is capable to perform the action,
· @return Returns 1 if capable, 0 otherwise
· */
/*!
Checks if cred->uid user is capable to perform the action,
@return Returns 1 if capable, 0 otherwise
*/
gid_t gids[64];
int nr_gids = 64;
struct passwd *pw;
......@@ -249,16 +242,16 @@ check_acl(int node, struct Creds *cred)
return 0;
}
//! Find if user is ok to execute command
//! Find if user is ok to exec cmd
int
acl_is_capable(int cmd, int node, struct Creds *cred)
{
· /*!
· Checks if cred->uid user is capable executing command cmd.
· Root is always capable, only CMD_CALL commands are allowed here
· @return Returns 1 if allowed, 0 otherwise
· */
/*!
Checks if cred->uid user is capable executing command cmd.
Root is always capable, only CMD_CALL commands are allowed here
@return Returns 1 if allowed, 0 otherwise
*/
// root always capable
if (cred->uid == 0)
return 1;
......@@ -274,11 +267,10 @@ acl_is_capable(int cmd, int node, struct Creds *cred)
int
acl_can_connect(struct Creds *cred)
{
· /*!
· Checks if user with user id cred->uid can connect comar.
· @return Returns 1 if can connect, 0 otherwise
· */
/*!
Checks if user with user id cred->uid can connect comar.
@return Returns 1 if can connect, 0 otherwise
*/
gid_t gids[64];
int nr_gids = 64;
struct passwd *pw;
......
......@@ -17,7 +17,7 @@
#include "cfg.h"
#include "process.h"
/* global option variables with defaults */
// global option variables with defaults
char *cfg_model_file = "/etc/comar/model.xml";
char *cfg_data_dir = "/var/db/comar";
char *cfg_socket_name = "/var/run/comar.socket";
......@@ -59,7 +59,7 @@ static char *shortopts = "m:d:s:g:phv";
static void
print_usage(void)
{
puts(
puts(
_("Usage: comar [OPTIONS]\n"
"Pardus configuration manager.\n"
" -m, --model [FILE] Use the given xml model file.\n"
......@@ -93,6 +93,9 @@ print_version(void)
void
cfg_init(int argc, char *argv[])
{
/*!
Parses command line options
*/
int c, i, j;
while ((c = getopt_long(argc, argv, shortopts, longopts, &i)) != -1) {
......
......@@ -307,15 +307,20 @@ static PyMethodDef methods[] = {
{ NULL, NULL, 0, NULL }
};
//! Basic initialization
void
csl_setup(void)
{
Py_Initialize();
}
//! Log exceptions
static void
log_exception(void)
{
/*! Log exceptions as errors.
\sa log.c log_error
*/
PyObject *pType;
PyObject *pValue;
PyObject *pTrace;
......@@ -323,6 +328,7 @@ log_exception(void)
char *vStr = "";
long lineno = 0;
// Retrieve the error indicator into variables
PyErr_Fetch(&pType, &pValue, &pTrace);
if (!pType) {
log_error("csl.c log_exception() called when there isn't an exception\n");
......@@ -502,6 +508,7 @@ csl_execute(char *code, size_t size, const char *func_name, struct pack *pak, ch
return 0;
}
//! Finish
void
csl_cleanup(void)
{
......
This diff is collapsed.
......@@ -59,11 +59,8 @@ job_send_result(int cmd, const char *data, size_t size)
static int
do_register(int node, const char *app, const char *fname)
{
· /*!
Register script by first testing it by compiling.
· If it compiles well, put script. \sa db_put_script csl_compile
*/
/*! Register script by first testing it by compiling
If it compiles well, put script. \sa db_put_script csl_compile*/
char *buf;
char *code;
size_t codelen;
......@@ -150,13 +147,11 @@ do_event(const char *event, int node, const char *app, struct pack *p)
static int
do_execute(int node, const char *app, struct pack *pak)
{
· /*!
Load the app code and execute it with python/c api @see csl.c
· If execution lasts more than 6 seconds, logs this information @see log_info
· Returns 0 on a successfull call, returns error returned by csl execute function otherwise
· \sa csl.c
· */
/*! Load the app code and execute it with python/c api @see csl.c
If execution lasts more than 6 seconds, logs this information @see log_info
Returns 0 on a successfull call, returns error returned by csl execute function otherwise
\sa csl.c
*/
struct timeval start, end;
unsigned long msec;
struct pack *p = NULL;
......@@ -234,11 +229,8 @@ exec_proc(void)
static int
do_call(int node, struct pack *pak)
{
· /*!
Get scripts and run them, send results and return
· @return Returns 0
*/
/*! Get scripts and run them, send results and return
@return Returns 0 */
struct pack *p = NULL;
char *apps;
int ok = 0;
......@@ -362,10 +354,9 @@ do_dump_profile(void)
static void
job_proc(void)
{
· /*!
· Listen for incoming requests and process the commands.
· */
/*!
Listen for incoming requests and process the commands.
*/
struct ipc_struct ipc;
struct pack *p;
struct ProcChild *sender;
......@@ -374,7 +365,7 @@ job_proc(void)
size_t size;
p = pack_new(256);
// wait untill theres something to listen
// wait untill theres something to listen
while (1) {
if (1 == proc_listen(&sender, &cmd, &size, 1)) break;
}
......
......@@ -47,12 +47,10 @@ pidstamp(FILE *f)
static void
log_print(const char *fmt, va_list ap, int error)
{
· /*!
Writes log to file (cfg_log_file_name) or stdout according to cfg_log_* options
· comar version, process id, timestamp and errors(if any) are written
· \sa cfg.c
· */
/*! Writes log to file (cfg_log_file_name) or stdout according to cfg_log_* options
comar version, process id, timestamp and errors(if any) are written
\sa cfg.c
*/
if (cfg_log_console) {
pidstamp(stdout);
vprintf(fmt, ap);
......@@ -89,11 +87,10 @@ log_start(void)
void
log_error(const char *fmt, ...)
{
· /*!
· Same as log_info, if this function is called instead, writes
· information as an 'error' to log file
· */
/*!
Same as log_info, if this function is called instead, writes
information as an 'error' to log file
*/
va_list ap;
va_start(ap, fmt);
......@@ -105,12 +102,11 @@ log_error(const char *fmt, ...)
void
log_info(const char *fmt, ...)
{
· /*!
· Prints log info of variable arguments with log_print function.
· Console or file usage depends on cfg_log_* options
· \sa log_print cfg.c
· */
/*!
Prints log info of variable arguments with log_print function.
Console or file usage depends on cfg_log_* options
\sa log_print cfg.c
*/
va_list ap;
va_start(ap, fmt);
......
......@@ -39,11 +39,11 @@ stop_running_comar(void)
size_t size;
int sock;
// create socket
// create socket
sock = socket(PF_LOCAL, SOCK_STREAM, 0);
if (sock == -1) return;
// a local socket
// a local socket
name.sun_family = AF_LOCAL;
strncpy(name.sun_path, cfg_socket_name, sizeof (name.sun_path));
size = (offsetof (struct sockaddr_un, sun_path) + strlen (name.sun_path) + 1);
......@@ -152,6 +152,5 @@ main(int argc, char *argv[])
}
}
}
return 0;
}
......@@ -64,11 +64,10 @@ hash_string(const unsigned char *str, int len)
static int
prepare_tables(int max_nodes, size_t str_size)
{
· /*!
· @return Returns 0 if successfully allocates memory for nodes, node table and paths,
· -1 otherwise
· */
/*!
@return Returns 0 if successfully allocates memory for nodes, node table and paths,
-1 otherwise
*/
nodes = calloc(max_nodes, sizeof(struct node));
node_table = calloc(TABLE_SIZE, sizeof(struct node *));
paths = malloc(str_size);
......@@ -80,11 +79,10 @@ prepare_tables(int max_nodes, size_t str_size)
static int
add_node(int parent_no, const char *path, int type)
{
· /*!
· parent_no is depth of node. adds node with path and type (method)
· to node table
· */
/*!
parent_no is depth of node. adds node with path and type (method)
to node table
*/
struct node *n;
int val;
int len = strlen(path);
......@@ -115,12 +113,11 @@ static char *path_ptr = NULL;
static char *
build_path(iks *g, iks *o, iks *m)
{
· /*!
· Returns the 'name' attr of 'g' iks node (group)
· if 'm' is given, returns it as group.object.method (names)
· if 'o' is given, returns group.object (names)
· */
/*!
Returns the 'name' attr of 'g' iks node (group)
if 'm' is given, returns it as group.object.method (names)
if 'o' is given, returns group.object (names)
*/
if (path_ptr) {
path_ptr += strlen(path_ptr) + 1;
} else {
......@@ -170,13 +167,12 @@ build_arg(int no, int is_instance, const char *name)
int
model_init(void)
{
· /*!
· This function parses model.xml file (cfg_model_file)
· Converts model.xml's access levels and flags to ACL levels and
· flags, and loads into memory before deleting dom tree
· \sa cfg.c
· */
/*!
This function parses model.xml file (cfg_model_file)
Converts model.xml's access levels and flags to ACL levels and
flags, and loads into memory before deleting dom tree
\sa cfg.c
*/
iks *model;
iks *grp, *obj, *met;
int count = 0;
......@@ -198,6 +194,7 @@ model_init(void)
}
// FIXME: ugly code ahead, split into functions and simplify
// i agree
// scan the model
for (grp = iks_first_tag(model); grp; grp = iks_next_tag(grp)) {
......@@ -244,7 +241,7 @@ model_init(void)
}
}
// size is counted to alloc mem for paths
// size is counted to alloc mem for paths
// prepare data structures
if (prepare_tables(count, size)) return -1;
......@@ -335,11 +332,9 @@ model_lookup_class(const char *path)
int
model_lookup_method(const char *path)
{
· /*!
Lookup a method in node table.
· @return If found, returns its number in table, returns -1 otherwise·
· */
/*! Lookup a method in node table.
@return If found, returns its number in table, returns -1 otherwise
*/
struct node *n;
int val;
......@@ -356,11 +351,10 @@ model_lookup_method(const char *path)
int
model_lookup_notify(const char *path)
{
· /*!
· If specified path's record in node table has a type of 'notify'
· returns its number in table, returns -1 otherwise
· */
/*!
If specified path's record in node table has a type of 'notify'
returns its number in table, returns -1 otherwise
*/
struct node *n;
int val;
......@@ -377,11 +371,9 @@ model_lookup_notify(const char *path)
int
model_parent(int node_no)
{
· /*!
if node_no numbered record in node table is a method, returns its parent number
· else returns node_no
· */
/*! if node_no numbered record in node table is a method, returns its parent number
else returns node_no
*/
struct node *n;
n = &nodes[node_no];
......@@ -414,10 +406,9 @@ model_get_path(int node_no)
int
model_has_argument(int node_no, const char *argname)
{
· /*!
· @return Returns 1 if argname is found in node table, 0 otherwise
· */
/*!
@return Returns 1 if argname is found in node table, 0 otherwise
*/
struct node *n;
int max, i;
const char *t;
......@@ -491,12 +482,11 @@ model_acl_set(int node_no, void *acldata)
void
model_acl_get(int node_no, void **acldatap, unsigned int *levelp)
{
· /*!
· This function gets 'acldata' and 'level' from node table, from record numbered 'node_no'
· \param acldatap is pointer to acldata
· \param levelp is pointer to level
· */
/*!
This function gets 'acldata' and 'level' from node table, from record numbered 'node_no'
\param acldatap is pointer to acldata
\param levelp is pointer to level
*/
struct node *n;
n = &nodes[node_no];
......@@ -513,12 +503,11 @@ model_acl_get(int node_no, void **acldatap, unsigned int *levelp)
int
model_next_class(int *class_nop)
{
· /*!
· Scans node table for class tags
· @return If found, returns 1 and sets the node number to given argument (class_nop) \n
· Returns 0 if no classes found
· */
/*!
Scans node table for class tags
@return If found, returns 1 and sets the node number to given argument (class_nop) \n
Returns 0 if no classes found
*/
int no;
struct node *n;
......@@ -534,3 +523,4 @@ model_next_class(int *class_nop)
*class_nop = -1;
return 0;
}
......@@ -20,11 +20,10 @@
void *
notify_alloc(void)
{
· /*!
· Allocates memory for notifies and returns pointer to allocated memory
· Returns Null on error.
· */
/*!
Allocates memory for notifies and returns pointer to allocated memory
Returns Null on error.
*/
int size;
size = (model_max_notifications + 7)/ 8;
......
......@@ -40,14 +40,14 @@ handle_signals(void)
struct sigaction dfl;
act.sa_handler = handle_sigterm;
/*! initialize and empty a signal set. Signals are to be blocked while executing handle_sigterm */
/*! initialize and empty a signal set. Signals are to be blocked while executing handle_sigterm */
sigemptyset(&act.sa_mask);
act.sa_flags = 0; /*!< special flags */
ign.sa_handler = SIG_IGN;
sigemptyset(&ign.sa_mask);
ign.sa_flags = 0;
dfl.sa_handler = SIG_DFL; /*!< default signal handling. */
sigemptyset(&dfl.sa_mask);
dfl.sa_flags = 0;
......@@ -96,15 +96,14 @@ proc_get_rpc(void)
return &my_proc.children[0];
}
//! Add a child
//! add a child
static struct ProcChild *
add_child(pid_t pid, int to, int from, const char *desc)
{
· /*!
· Adds a child process with given arguments to process
· @return Returns added child process
· */
/*!
Adds a child process with given arguments to process
@return Returns added child process
*/
int i;
i = my_proc.nr_children;
......@@ -148,11 +147,10 @@ rem_child(int nr)
static void
stop_children(void)
{
· /*!
· Send SIGTERM to all child processes, wait for 3 seconds
· if they resist, kill'em all
· */
/*!
Send SIGTERM to all child processes, wait for 3 seconds
if they resist, kill'em all
*/
struct timeval start;
struct timeval cur;
struct timeval tv;
......@@ -229,14 +227,13 @@ proc_finish(void)
struct ProcChild *
proc_fork(void (*child_func)(void), const char *desc)
{
· /*!
· Child process fork function, child process continues from child_func
· \param desc is description, process name
· @return Returns Null on error
· */
/*!
Child process fork function, child process continues from child_func
\param desc is description, process name
@return Returns Null on error
*/
pid_t pid;
int fdr[2], fdw[2];
int fdr[2], fdw[2]; // file descriptors to read and write from pipe
int i;
pipe(fdr);
......@@ -244,7 +241,7 @@ proc_fork(void (*child_func)(void), const char *desc)
pid = fork();
if (pid == -1) return NULL;
if (pid == 0) {
if (pid == 0) { // child process
// new child process starts
// we have to close unneeded pipes inherited from the parent
if (my_proc.parent.to != -1) close(my_proc.parent.to);
......@@ -310,12 +307,11 @@ proc_setup_fds(fd_set *fds)
int
proc_select_fds(fd_set *fds, int max, struct ProcChild **senderp, int *cmdp, size_t *sizep, int timeout)
{
· /*!
· Listen incoming requests with 'select()'
· Sets command, data size and returns 1 if there's something to listen
· Returns 0 otherwise
· */
/*!
Listen incoming requests with 'select()'
Sets command, data size and returns 1 if there's something to listen
Returns 0 otherwise
*/
unsigned int ipc;
struct timeval tv, *tvptr;
int sock;
......
......@@ -104,25 +104,24 @@ get_size(const unsigned char *buf)
static int
create_pipe(const char *pipe_name)
{
· /*!
· Creates a pipe, with listen. length of the queue is 5
· @return Returns -2 if can't assign address to socket \n
· Returns -3 if can't listen requests
· */
/*!
Creates a pipe, with listen. length of the queue is 5
@return Returns -2 if can't assign address to socket \n
Returns -3 if can't listen requests
*/
struct sockaddr_un name;
size_t size;
pipe_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
if (pipe_fd < 0) return -1;
// delete cfg_socket_name
// delete cfg_socket_name
unlink(pipe_name);
name.sun_family = AF_LOCAL;
strncpy(name.sun_path, pipe_name, sizeof(name.sun_path));
size = (offsetof(struct sockaddr_un, sun_path) + strlen(name.sun_path) + 1);
// assign address to socket
// assign address to socket
if (0 != bind(pipe_fd, (struct sockaddr *) &name, size)) {
close(pipe_fd);
return -2;
......@@ -130,7 +129,7 @@ create_pipe(const char *pipe_name)
chmod(pipe_name, 0666);
// to enable connection requests on the socket ( a server socket )
// to enable connection requests on the socket ( a server socket )
if (0 != listen(pipe_fd, 5)) {
close(pipe_fd);
return -3;
......@@ -143,10 +142,10 @@ create_pipe(const char *pipe_name)
static int
get_peer(int sock, struct Creds *cred)
{
· /*!
· Gets options of sock, and fills cred according to these options
· @return Returns 0. Returns -1 on error.
· */
/*!
Gets options of sock, and fills cred according to these options
@return Returns 0. Returns -1 on error.
*/
// NOTE: this implementation requires a linux kernel
struct {
pid_t pid;
......@@ -256,10 +255,9 @@ get_arg(struct arg_s *args, char **argp, size_t *sizep)
static int
write_rpc(struct connection *c, unsigned int cmd, int id, const char *buffer, size_t size)
{
· /*!
· Checks the command cmd, and sends c's socket the answer
· */
/*!
Checks the command cmd, and sends c's socket the answer
*/
unsigned char head[8];
head[4] = (id >> 24) & 0xFF;
......@@ -300,11 +298,10 @@ write_rpc(struct connection *c, unsigned int cmd, int id, const char *buffer, si
static int
parse_rpc(struct connection *c)
{
· /*!
This is parser function for RPC
· According to command in c's buffer, checks for permissions
· and executes, denies etc. the command
· */
/*! This is parser function for RPC
According to command in c's buffer, checks for permissions
and executes, denies etc. the command
*/
struct ipc_struct ipc;
struct arg_s args;
......@@ -501,7 +498,7 @@ read_rpc(struct connection *c)
}
}
if (c->pos == c->data_size + 8) {
if (parse_rpc(c)) return -1;
if (read_rpc(c)) return -1;
c->data_size = 0;
c->pos = 0;
}
......@@ -526,7 +523,6 @@ add_rpc_fds(fd_set *fds, int max)
}
return max;
}
//! This is handler function for custom rpc commands
void
handle_rpc_fds(fd_set *fds)
......@@ -652,11 +648,10 @@ rpc_proc(void)
void
rpc_unix_start(void)
{
· /*!
· Fork RPC process