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

revert last merge

üst a4e82db9
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#ifndef ACL_H #ifndef ACL_H
#define ACL_H 1 #define ACL_H 1
//! A user id and group id only
struct Creds { struct Creds {
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
......
...@@ -12,11 +12,6 @@ ...@@ -12,11 +12,6 @@
#include "utility.h" #include "utility.h"
//! Database operations
/*!
All database related functions are here
*/
int db_init(void); int db_init(void);
int db_put_script(int node_no, const char *app, const char *buffer, size_t size); int db_put_script(int node_no, const char *app, const char *buffer, size_t size);
......
...@@ -16,29 +16,27 @@ extern int shutdown_activated; ...@@ -16,29 +16,27 @@ extern int shutdown_activated;
struct ipc_source { struct ipc_source {
void *chan; void *chan;
unsigned int cookie; /*!< To detect process */ unsigned int cookie;
int id; int id;
unsigned char lang[4]; /*!< Messages language */ unsigned char lang[4];
}; };
//! A basic process structure
struct ProcChild { struct ProcChild {
int from; /*!< FIXME. */ int from;
int to; /*!< FIXME. */ int to;
pid_t pid; /*!< Process id */ pid_t pid;
const char *desc; /*!< Description of process, also its name */ const char *desc;
// keep track of command source, used by job_cancel // keep track of command source, used by job_cancel
struct ipc_source source; struct ipc_source source;
}; };
//! A Process
struct Proc { struct Proc {
// parent info // parent info
struct ProcChild parent; /*!< Parent of this process */ struct ProcChild parent;
const char *desc; /*!< Name of this process */ const char *desc;
// children info // children info
int nr_children; /*!< Number of children */ int nr_children;
int max_children; /*!< Maximum children */ int max_children;
struct ProcChild *children; struct ProcChild *children;
}; };
...@@ -47,12 +45,13 @@ struct ipc_struct { ...@@ -47,12 +45,13 @@ struct ipc_struct {
int node; int node;
}; };
extern struct Proc my_proc; /*!< Per process global variable */ // per process global variable
extern struct Proc my_proc;
//! For readability of send_cmd/data functions // for readability of send_cmd/data functions
#define TO_PARENT NULL #define TO_PARENT NULL
//! ipc commands // ipc commands
enum { enum {
CMD_FINISH = 0, CMD_FINISH = 0,
CMD_RESULT, CMD_RESULT,
......
...@@ -19,12 +19,11 @@ int utf8_is_valid(const char *str, size_t size); ...@@ -19,12 +19,11 @@ int utf8_is_valid(const char *str, size_t size);
unsigned long time_diff(struct timeval *start, struct timeval *end); unsigned long time_diff(struct timeval *start, struct timeval *end);
//! A package struct
struct pack { struct pack {
unsigned char *buffer; /*!< Buffer that carries data */ unsigned char *buffer;
size_t max; /*!< Max size of data */ size_t max;
size_t used; /*!< Used size */ size_t used;
unsigned int pos; /*!< Position in data */ unsigned int pos;
}; };
struct pack *pack_new(size_t min_size); struct pack *pack_new(size_t min_size);
......
...@@ -37,11 +37,12 @@ static unsigned int acl_nr_allowed_gids; ...@@ -37,11 +37,12 @@ static unsigned int acl_nr_allowed_gids;
static int static int
count_groups(iks *tag, int class_no) count_groups(iks *tag, int class_no)
{ {
/*! /*!
Returns the number of group tags in child tags of 'tag' Returns the number of group tags in child tags of 'tag'
It also counts group tags under class tag ( class permissions ) It also counts group tags under class tag ( class permissions )
@return Returns number of groups @return Returns number of groups
*/ */
iks *x; iks *x;
unsigned int nr = 0; unsigned int nr = 0;
// global permissions // global permissions
...@@ -62,10 +63,11 @@ count_groups(iks *tag, int class_no) ...@@ -62,10 +63,11 @@ count_groups(iks *tag, int class_no)
static void static void
add_allowed(gid_t gid) add_allowed(gid_t gid)
{ {
/*! /*!
This function allocates memory for allowed group id's. @see acl_allowed_gids This function allocates memory for allowed group id's. @see acl_allowed_gids
Every group is added once Every group is added once
*/ */
static unsigned int max_allowed = 0; static unsigned int max_allowed = 0;
unsigned int i; unsigned int i;
...@@ -92,11 +94,12 @@ add_allowed(gid_t gid) ...@@ -92,11 +94,12 @@ add_allowed(gid_t gid)
static void static void
add_group(iks *tag, int level, struct acl_class *ac) 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) 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 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 \param ac is the allocated memory for acl_group structure \param level is permissions level
*/ */
struct acl_group *ag; struct acl_group *ag;
char *name; char *name;
struct group *grp; struct group *grp;
...@@ -119,11 +122,12 @@ add_group(iks *tag, int level, struct acl_class *ac) ...@@ -119,11 +122,12 @@ add_group(iks *tag, int level, struct acl_class *ac)
static void static void
add_groups(iks *tag, int class_no, int level, struct acl_class *ac) 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 · Searches 'tag' in 'group' and 'class' tags, calls add_group function with found tags
level and acl_class is passed to add_group · level and acl_class is passed to add_group
\sa add_group · \sa add_group
*/ · */
iks *x; iks *x;
// global permissions // global permissions
for (x = iks_find(tag, "group"); x; x = iks_next_tag(x)) { for (x = iks_find(tag, "group"); x; x = iks_next_tag(x)) {
...@@ -142,11 +146,12 @@ add_groups(iks *tag, int class_no, int level, struct acl_class *ac) ...@@ -142,11 +146,12 @@ add_groups(iks *tag, int class_no, int level, struct acl_class *ac)
static void static void
set_class(iks *model, int class_no) set_class(iks *model, int class_no)
{ {
/*! · /*!
Allocates memory for all found 'group's in 'model' @see count_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 · Then add_groups is called and acl_class is put in node table
\sa add_groups · \sa add_groups
*/ · */
struct acl_class *ac; struct acl_class *ac;
int nr_groups = 0; int nr_groups = 0;
...@@ -169,10 +174,11 @@ set_class(iks *model, int class_no) ...@@ -169,10 +174,11 @@ set_class(iks *model, int class_no)
void void
acl_init(void) acl_init(void)
{ {
/*! · /*!
Loads /etc/comar/security-policy.xml file · Loads /etc/comar/security-policy.xml file
For all classes in model.xml file look in security-policy if theres a match · For all classes in model.xml file, look in security-policy if theres a match
*/ · */
iks *policy; iks *policy;
iks *model; iks *model;
int class_no; int class_no;
...@@ -205,10 +211,11 @@ acl_init(void) ...@@ -205,10 +211,11 @@ acl_init(void)
static int static int
check_acl(int node, struct Creds *cred) check_acl(int node, struct Creds *cred)
{ {
/*! · /*!
Checks if cred->uid user is capable to perform the action, · Checks if cred->uid user is capable to perform the action,
@return Returns 1 if capable, 0 otherwise · @return Returns 1 if capable, 0 otherwise
*/ · */
gid_t gids[64]; gid_t gids[64];
int nr_gids = 64; int nr_gids = 64;
struct passwd *pw; struct passwd *pw;
...@@ -242,16 +249,16 @@ check_acl(int node, struct Creds *cred) ...@@ -242,16 +249,16 @@ check_acl(int node, struct Creds *cred)
return 0; return 0;
} }
//! Find if user is ok to exec cmd //! Find if user is ok to execute command
int int
acl_is_capable(int cmd, int node, struct Creds *cred) acl_is_capable(int cmd, int node, struct Creds *cred)
{ {
/*! · /*!
Checks if cred->uid user is capable executing command cmd. · Checks if cred->uid user is capable executing command cmd.
Root is always capable, only CMD_CALL commands are allowed here · Root is always capable, only CMD_CALL commands are allowed here
@return Returns 1 if allowed, 0 otherwise · @return Returns 1 if allowed, 0 otherwise
*/ · */
// root always capable
if (cred->uid == 0) if (cred->uid == 0)
return 1; return 1;
...@@ -267,10 +274,11 @@ acl_is_capable(int cmd, int node, struct Creds *cred) ...@@ -267,10 +274,11 @@ acl_is_capable(int cmd, int node, struct Creds *cred)
int int
acl_can_connect(struct Creds *cred) acl_can_connect(struct Creds *cred)
{ {
/*! · /*!
Checks if user with user id cred->uid can connect comar. · Checks if user with user id cred->uid can connect comar.
@return Returns 1 if can connect, 0 otherwise · @return Returns 1 if can connect, 0 otherwise
*/ · */
gid_t gids[64]; gid_t gids[64];
int nr_gids = 64; int nr_gids = 64;
struct passwd *pw; struct passwd *pw;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "cfg.h" #include "cfg.h"
#include "process.h" #include "process.h"
// global option variables with defaults /* global option variables with defaults */
char *cfg_model_file = "/etc/comar/model.xml"; char *cfg_model_file = "/etc/comar/model.xml";
char *cfg_data_dir = "/var/db/comar"; char *cfg_data_dir = "/var/db/comar";
char *cfg_socket_name = "/var/run/comar.socket"; char *cfg_socket_name = "/var/run/comar.socket";
...@@ -59,7 +59,7 @@ static char *shortopts = "m:d:s:g:phv"; ...@@ -59,7 +59,7 @@ static char *shortopts = "m:d:s:g:phv";
static void static void
print_usage(void) print_usage(void)
{ {
puts( puts(
_("Usage: comar [OPTIONS]\n" _("Usage: comar [OPTIONS]\n"
"Pardus configuration manager.\n" "Pardus configuration manager.\n"
" -m, --model [FILE] Use the given xml model file.\n" " -m, --model [FILE] Use the given xml model file.\n"
...@@ -93,9 +93,6 @@ print_version(void) ...@@ -93,9 +93,6 @@ print_version(void)
void void
cfg_init(int argc, char *argv[]) cfg_init(int argc, char *argv[])
{ {
/*!
Parses command line options
*/
int c, i, j; int c, i, j;
while ((c = getopt_long(argc, argv, shortopts, longopts, &i)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, &i)) != -1) {
......
...@@ -307,20 +307,15 @@ static PyMethodDef methods[] = { ...@@ -307,20 +307,15 @@ static PyMethodDef methods[] = {
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
//! Basic initialization
void void
csl_setup(void) csl_setup(void)
{ {
Py_Initialize(); Py_Initialize();
} }
//! Log exceptions
static void static void
log_exception(void) log_exception(void)
{ {
/*! Log exceptions as errors.
\sa log.c log_error
*/
PyObject *pType; PyObject *pType;
PyObject *pValue; PyObject *pValue;
PyObject *pTrace; PyObject *pTrace;
...@@ -328,7 +323,6 @@ log_exception(void) ...@@ -328,7 +323,6 @@ log_exception(void)
char *vStr = ""; char *vStr = "";
long lineno = 0; long lineno = 0;
// Retrieve the error indicator into variables
PyErr_Fetch(&pType, &pValue, &pTrace); PyErr_Fetch(&pType, &pValue, &pTrace);
if (!pType) { if (!pType) {
log_error("csl.c log_exception() called when there isn't an exception\n"); log_error("csl.c log_exception() called when there isn't an exception\n");
...@@ -508,7 +502,6 @@ csl_execute(char *code, size_t size, const char *func_name, struct pack *pak, ch ...@@ -508,7 +502,6 @@ csl_execute(char *code, size_t size, const char *func_name, struct pack *pak, ch
return 0; return 0;
} }
//! Finish
void void
csl_cleanup(void) csl_cleanup(void)
{ {
......
This diff is collapsed.
...@@ -59,8 +59,11 @@ job_send_result(int cmd, const char *data, size_t size) ...@@ -59,8 +59,11 @@ job_send_result(int cmd, const char *data, size_t size)
static int static int
do_register(int node, const char *app, const char *fname) 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 *buf;
char *code; char *code;
size_t codelen; size_t codelen;
...@@ -147,11 +150,13 @@ do_event(const char *event, int node, const char *app, struct pack *p) ...@@ -147,11 +150,13 @@ do_event(const char *event, int node, const char *app, struct pack *p)
static int static int
do_execute(int node, const char *app, struct pack *pak) 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 Load the app code and execute it with python/c api @see csl.c
Returns 0 on a successfull call, returns error returned by csl execute function otherwise · If execution lasts more than 6 seconds, logs this information @see log_info
\sa csl.c · Returns 0 on a successfull call, returns error returned by csl execute function otherwise
*/ · \sa csl.c
· */
struct timeval start, end; struct timeval start, end;
unsigned long msec; unsigned long msec;
struct pack *p = NULL; struct pack *p = NULL;
...@@ -229,8 +234,11 @@ exec_proc(void) ...@@ -229,8 +234,11 @@ exec_proc(void)
static int static int
do_call(int node, struct pack *pak) 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; struct pack *p = NULL;
char *apps; char *apps;
int ok = 0; int ok = 0;
...@@ -354,9 +362,10 @@ do_dump_profile(void) ...@@ -354,9 +362,10 @@ do_dump_profile(void)
static void static void
job_proc(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 ipc_struct ipc;
struct pack *p; struct pack *p;
struct ProcChild *sender; struct ProcChild *sender;
...@@ -365,7 +374,7 @@ job_proc(void) ...@@ -365,7 +374,7 @@ job_proc(void)
size_t size; size_t size;
p = pack_new(256); p = pack_new(256);
// wait untill theres something to listen // wait untill theres something to listen
while (1) { while (1) {
if (1 == proc_listen(&sender, &cmd, &size, 1)) break; if (1 == proc_listen(&sender, &cmd, &size, 1)) break;
} }
......
...@@ -47,10 +47,12 @@ pidstamp(FILE *f) ...@@ -47,10 +47,12 @@ pidstamp(FILE *f)
static void static void
log_print(const char *fmt, va_list ap, int error) 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 Writes log to file (cfg_log_file_name) or stdout according to cfg_log_* options
\sa cfg.c · comar version, process id, timestamp and errors(if any) are written
*/ · \sa cfg.c
· */
if (cfg_log_console) { if (cfg_log_console) {
pidstamp(stdout); pidstamp(stdout);
vprintf(fmt, ap); vprintf(fmt, ap);
...@@ -87,10 +89,11 @@ log_start(void) ...@@ -87,10 +89,11 @@ log_start(void)
void void
log_error(const char *fmt, ...) log_error(const char *fmt, ...)
{ {
/*! · /*!
Same as log_info, if this function is called instead, writes · Same as log_info, if this function is called instead, writes
information as an 'error' to log file · information as an 'error' to log file
*/ · */
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
...@@ -102,11 +105,12 @@ log_error(const char *fmt, ...) ...@@ -102,11 +105,12 @@ log_error(const char *fmt, ...)
void void
log_info(const char *fmt, ...) log_info(const char *fmt, ...)
{ {
/*! · /*!
Prints log info of variable arguments with log_print function. · Prints log info of variable arguments with log_print function.
Console or file usage depends on cfg_log_* options · Console or file usage depends on cfg_log_* options
\sa log_print cfg.c · \sa log_print cfg.c
*/ · */
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
......
...@@ -39,11 +39,11 @@ stop_running_comar(void) ...@@ -39,11 +39,11 @@ stop_running_comar(void)
size_t size; size_t size;
int sock; int sock;
// create socket // create socket
sock = socket(PF_LOCAL, SOCK_STREAM, 0); sock = socket(PF_LOCAL, SOCK_STREAM, 0);
if (sock == -1) return; if (sock == -1) return;
// a local socket // a local socket
name.sun_family = AF_LOCAL; name.sun_family = AF_LOCAL;
strncpy(name.sun_path, cfg_socket_name, sizeof (name.sun_path)); strncpy(name.sun_path, cfg_socket_name, sizeof (name.sun_path));
size = (offsetof (struct sockaddr_un, sun_path) + strlen (name.sun_path) + 1); size = (offsetof (struct sockaddr_un, sun_path) + strlen (name.sun_path) + 1);
...@@ -152,5 +152,6 @@ main(int argc, char *argv[]) ...@@ -152,5 +152,6 @@ main(int argc, char *argv[])
} }
} }
} }
return 0; return 0;
} }
...@@ -64,10 +64,11 @@ hash_string(const unsigned char *str, int len) ...@@ -64,10 +64,11 @@ hash_string(const unsigned char *str, int len)
static int static int
prepare_tables(int max_nodes, size_t str_size) prepare_tables(int max_nodes, size_t str_size)
{ {
/*! · /*!
@return Returns 0 if successfully allocates memory for nodes, node table and paths, · @return Returns 0 if successfully allocates memory for nodes, node table and paths,
-1 otherwise · -1 otherwise
*/ · */
nodes = calloc(max_nodes, sizeof(struct node)); nodes = calloc(max_nodes, sizeof(struct node));
node_table = calloc(TABLE_SIZE, sizeof(struct node *)); node_table = calloc(TABLE_SIZE, sizeof(struct node *));
paths = malloc(str_size); paths = malloc(str_size);
...@@ -79,10 +80,11 @@ prepare_tables(int max_nodes, size_t str_size) ...@@ -79,10 +80,11 @@ prepare_tables(int max_nodes, size_t str_size)
static int static int
add_node(int parent_no, const char *path, int type) add_node(int parent_no, const char *path, int type)
{ {
/*! · /*!
parent_no is depth of node. adds node with path and type (method) · parent_no is depth of node. adds node with path and type (method)
to node table · to node table
*/ · */
struct node *n; struct node *n;
int val; int val;
int len = strlen(path); int len = strlen(path);
...@@ -113,11 +115,12 @@ static char *path_ptr = NULL; ...@@ -113,11 +115,12 @@ static char *path_ptr = NULL;
static char * static char *
build_path(iks *g, iks *o, iks *m) build_path(iks *g, iks *o, iks *m)
{ {
/*! · /*!
Returns the 'name' attr of 'g' iks node (group) · Returns the 'name' attr of 'g' iks node (group)
if 'm' is given, returns it as group.object.method (names) · if 'm' is given, returns it as group.object.method (names)
if 'o' is given, returns group.object (names) · if 'o' is given, returns group.object (names)
*/ · */
if (path_ptr) { if (path_ptr) {
path_ptr += strlen(path_ptr) + 1; path_ptr += strlen(path_ptr) + 1;
} else { } else {
...@@ -167,12 +170,13 @@ build_arg(int no, int is_instance, const char *name) ...@@ -167,12 +170,13 @@ build_arg(int no, int is_instance, const char *name)
int int
model_init(void) model_init(void)
{ {
/*! · /*!
This function parses model.xml file (cfg_model_file) · This function parses model.xml file (cfg_model_file)
Converts model.xml's access levels and flags to ACL levels and · Converts model.xml's access levels and flags to ACL levels and
flags, and loads into memory before deleting dom tree · flags, and loads into memory before deleting dom tree
\sa cfg.c · \sa cfg.c
*/ · */
iks *model; iks *model;
iks *grp, *obj, *met; iks *grp, *obj, *met;
int count = 0; int count = 0;
...@@ -194,7 +198,6 @@ model_init(void) ...@@ -194,7 +198,6 @@ model_init(void)
} }
// FIXME: ugly code ahead, split into functions and simplify // FIXME: ugly code ahead, split into functions and simplify
// i agree
// scan the model // scan the model
for (grp = iks_first_tag(model); grp; grp = iks_next_tag(grp)) { for (grp = iks_first_tag(model); grp; grp = iks_next_tag(grp)) {
...@@ -241,7 +244,7 @@ model_init(void) ...@@ -241,7 +244,7 @@ model_init(void)
} }
} }
// size is counted to alloc mem for paths // size is counted to alloc mem for paths
// prepare data structures // prepare data structures
if (prepare_tables(count, size)) return -1; if (prepare_tables(count, size)) return -1;
...@@ -332,9 +335,11 @@ model_lookup_class(const char *path) ...@@ -332,9 +335,11 @@ model_lookup_class(const char *path)
int int
model_lookup_method(const char *path) 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; struct node *n;
int val; int val;
...@@ -351,10 +356,11 @@ model_lookup_method(const char *path) ...@@ -351,10 +356,11 @@ model_lookup_method(const char *path)
int int
model_lookup_notify(const char *path) model_lookup_notify(const char *path)
{ {
/*! · /*!
If specified path's record in node table has a type of 'notify' · If specified path's record in node table has a type of 'notify'
returns its number in table, returns -1 otherwise · returns its number in table, returns -1 otherwise
*/ · */
struct node *n; struct node *n;
int val; int val;
...@@ -371,9 +377,11 @@ model_lookup_notify(const char *path) ...@@ -371,9 +377,11 @@ model_lookup_notify(const char *path)
int int
model_parent(int node_no) 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; struct node *n;
n = &nodes[node_no]; n = &nodes[node_no];
...@@ -406,9 +414,10 @@ model_get_path(int node_no) ...@@ -406,9 +414,10 @@ model_get_path(int node_no)
int int
model_has_argument(int node_no, const char *argname) 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; struct node *n;
int max, i; int max, i;
const char *t; const char *t;
...@@ -482,11 +491,12 @@ model_acl_set(int node_no, void *acldata) ...@@ -482,11 +491,12 @@ model_acl_set(int node_no, void *acldata)
void void
model_acl_get(int node_no, void **acldatap, unsigned int *levelp) 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' · This function gets 'acldata' and 'level' from node table, from record numbered 'node_no'
\param acldatap is pointer to acldata · \param acldatap is pointer to acldata
\param levelp is pointer to level · \param levelp is pointer to level
*/ · */
struct node *n; struct node *n;
n = &nodes[node_no]; n = &nodes[node_no];
...@@ -503,11 +513,12 @@ model_acl_get(int node_no, void **acldatap, unsigned int *levelp) ...@@ -503,11 +513,12 @@ model_acl_get(int node_no, void **acldatap, unsigned int *levelp)
int int
model_next_class(int *class_nop) model_next_class(int *class_nop)
{ {
/*! · /*!
Scans node table for class tags · Scans node table for class tags
@return If found, returns 1 and sets the node number to given argument (class_nop) \n · @return If found, returns 1 and sets the node number to given argument (class_nop) \n
Returns 0 if no classes found · Returns 0 if no classes found
*/ · */
int no; int no;
struct node *n; struct node *n;
...@@ -523,4 +534,3 @@ model_next_class(int *class_nop) ...@@ -523,4 +534,3 @@ model_next_class(int *class_nop)
*class_nop = -1; *class_nop = -1;
return 0; return 0;
} }
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
void * void *
notify_alloc(void) notify_alloc(void)
{ {
/*! · /*!
Allocates memory for notifies and returns pointer to allocated memory · Allocates memory for notifies and returns pointer to allocated memory
Returns Null on error. · Returns Null on error.
*/ · */
int size; int size;
size = (model_max_notifications + 7)/ 8; size = (model_max_notifications + 7)/ 8;
......
...@@ -40,14 +40,14 @@ handle_signals(void) ...@@ -40,14 +40,14 @@ handle_signals(void)
struct sigaction dfl; struct sigaction dfl;
act.sa_handler = handle_sigterm; 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); sigemptyset(&act.sa_mask);
act.sa_flags = 0; /*!< special flags */ act.sa_flags = 0; /*!< special flags */
ign.sa_handler = SIG_IGN; ign.sa_handler = SIG_IGN;
sigemptyset(&ign.sa_mask); sigemptyset(&ign.sa_mask);
ign.sa_flags = 0; ign.sa_flags = 0;
dfl.sa_handler = SIG_DFL; /*!< default signal handling. */ dfl.sa_handler = SIG_DFL; /*!< default signal handling. */
sigemptyset(&dfl.sa_mask); sigemptyset(&dfl.sa_mask);
dfl.sa_flags = 0; dfl.sa_flags = 0;
...@@ -96,14 +96,15 @@ proc_get_rpc(void) ...@@ -96,14 +96,15 @@ proc_get_rpc(void)
return &my_proc.children[0]; return &my_proc.children[0];
} }
//! add a child //! Add a child
static struct ProcChild * static struct ProcChild *
add_child(pid_t pid, int to, int from, const char *desc) add_child(pid_t pid, int to, int from, const char *desc)
{ {
/*! · /*!
Adds a child process with given arguments to process · Adds a child process with given arguments to process
@return Returns added child process · @return Returns added child process
*/ · */
int i; int i;
i = my_proc.nr_children; i = my_proc.nr_children;
...@@ -147,10 +148,11 @@ rem_child(int nr) ...@@ -147,10 +148,11 @@ rem_child(int nr)
static void static void
stop_children(void) stop_children(void)
{ {
/*! · /*!
Send SIGTERM to all child processes, wait for 3 seconds · Send SIGTERM to all child processes, wait for 3 seconds
if they resist, kill'em all · if they resist, kill'em all
*/ · */
struct timeval start; struct timeval start;
struct timeval cur; struct timeval cur;
struct timeval tv; struct timeval tv;
...@@ -227,13 +229,14 @@ proc_finish(void) ...@@ -227,13 +229,14 @@ proc_finish(void)
struct ProcChild * struct ProcChild *
proc_fork(void (*child_func)(void), const char *desc) proc_fork(void (*child_func)(void), const char *desc)
{ {
/*! · /*!
Child process fork function, child process continues from child_func · Child process fork function, child process continues from child_func
\param desc is description, process name · \param desc is description, process name
@return Returns Null on error · @return Returns Null on error
*/ · */
pid_t pid; pid_t pid;
int fdr[2], fdw[2]; // file descriptors to read and write from pipe int fdr[2], fdw[2];
int i; int i;
pipe(fdr); pipe(fdr);
...@@ -241,7 +244,7 @@ proc_fork(void (*child_func)(void), const char *desc) ...@@ -241,7 +244,7 @@ proc_fork(void (*child_func)(void), const char *desc)
pid = fork(); pid = fork();
if (pid == -1) return NULL; if (pid == -1) return NULL;
if (pid == 0) { // child process if (pid == 0) {
// new child process starts // new child process starts
// we have to close unneeded pipes inherited from the parent // we have to close unneeded pipes inherited from the parent
if (my_proc.parent.to != -1) close(my_proc.parent.to); if (my_proc.parent.to != -1) close(my_proc.parent.to);
...@@ -307,11 +310,12 @@ proc_setup_fds(fd_set *fds) ...@@ -307,11 +310,12 @@ proc_setup_fds(fd_set *fds)
int int
proc_select_fds(fd_set *fds, int max, struct ProcChild **senderp, int *cmdp, size_t *sizep, int timeout) proc_select_fds(fd_set *fds, int max, struct ProcChild **senderp, int *cmdp, size_t *sizep, int timeout)
{ {
/*! · /*!
Listen incoming requests with 'select()' · Listen incoming requests with 'select()'
Sets command, data size and returns 1 if there's something to listen · Sets command, data size and returns 1 if there's something to listen
Returns 0 otherwise · Returns 0 otherwise
*/ · */
unsigned int ipc; unsigned int ipc;
struct timeval tv, *tvptr; struct timeval tv, *tvptr;
int sock; int sock;
......
...@@ -104,24 +104,25 @@ get_size(const unsigned char *buf) ...@@ -104,24 +104,25 @@ get_size(const unsigned char *buf)
static int static int
create_pipe(const char *pipe_name) create_pipe(const char *pipe_name)
{ {
/*! · /*!
Creates a pipe, with listen. length of the queue is 5 · Creates a pipe, with listen. length of the queue is 5
@return Returns -2 if can't assign address to socket \n · @return Returns -2 if can't assign address to socket \n
Returns -3 if can't listen requests · Returns -3 if can't listen requests
*/ · */
struct sockaddr_un name; struct sockaddr_un name;
size_t size; size_t size;
pipe_fd = socket(PF_LOCAL, SOCK_STREAM, 0); pipe_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
if (pipe_fd < 0) return -1; if (pipe_fd < 0) return -1;
// delete cfg_socket_name // delete cfg_socket_name
unlink(pipe_name); unlink(pipe_name);
name.sun_family = AF_LOCAL; name.sun_family = AF_LOCAL;
strncpy(name.sun_path, pipe_name, sizeof(name.sun_path)); strncpy(name.sun_path, pipe_name, sizeof(name.sun_path));
size = (offsetof(struct sockaddr_un, sun_path) + strlen(name.sun_path) + 1); 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)) { if (0 != bind(pipe_fd, (struct sockaddr *) &name, size)) {
close(pipe_fd); close(pipe_fd);
return -2; return -2;
...@@ -129,7 +130,7 @@ create_pipe(const char *pipe_name) ...@@ -129,7 +130,7 @@ create_pipe(const char *pipe_name)
chmod(pipe_name, 0666); 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)) { if (0 != listen(pipe_fd, 5)) {
close(pipe_fd); close(pipe_fd);
return -3; return -3;
...@@ -142,10 +143,10 @@ create_pipe(const char *pipe_name) ...@@ -142,10 +143,10 @@ create_pipe(const char *pipe_name)
static int static int
get_peer(int sock, struct Creds *cred) get_peer(int sock, struct Creds *cred)
{ {
/*! · /*!
Gets options of sock, and fills cred according to these options · Gets options of sock, and fills cred according to these options
@return Returns 0. Returns -1 on error. · @return Returns 0. Returns -1 on error.
*/ · */
// NOTE: this implementation requires a linux kernel // NOTE: this implementation requires a linux kernel
struct { struct {
pid_t pid; pid_t pid;
...@@ -255,9 +256,10 @@ get_arg(struct arg_s *args, char **argp, size_t *sizep) ...@@ -255,9 +256,10 @@ get_arg(struct arg_s *args, char **argp, size_t *sizep)
static int static int
write_rpc(struct connection *c, unsigned int cmd, int id, const char *buffer, size_t size) 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]; unsigned char head[8];
head[4] = (id >> 24) & 0xFF; head[4] = (id >> 24) & 0xFF;
...@@ -298,10 +300,11 @@ write_rpc(struct connection *c, unsigned int cmd, int id, const char *buffer, si ...@@ -298,10 +300,11 @@ write_rpc(struct connection *c, unsigned int cmd, int id, const char *buffer, si
static int static int
parse_rpc(struct connection *c) parse_rpc(struct connection *c)
{ {
/*! This is parser function for RPC · /*!
According to command in c's buffer, checks for permissions This is parser function for RPC
and executes, denies etc. the command · According to command in c's buffer, checks for permissions
*/ · and executes, denies etc. the command
· */
struct ipc_struct ipc; struct ipc_struct ipc;
struct arg_s args; struct arg_s args;
...@@ -498,7 +501,7 @@ read_rpc(struct connection *c) ...@@ -498,7 +501,7 @@ read_rpc(struct connection *c)
} }
} }
if (c->pos == c->data_size + 8) { if (c->pos == c->data_size + 8) {
if (read_rpc(c)) return -1; if (parse_rpc(c)) return -1;
c->data_size = 0; c->data_size = 0;
c->pos = 0; c->pos = 0;
} }
...@@ -523,6 +526,7 @@ add_rpc_fds(fd_set *fds, int max) ...@@ -523,6 +526,7 @@ add_rpc_fds(fd_set *fds, int max)
} }
return max; return max;
} }
//! This is handler function for custom rpc commands //! This is handler function for custom rpc commands
void void
handle_rpc_fds(fd_set *fds) handle_rpc_fds(fd_set *fds)
...@@ -648,10 +652,11 @@ rpc_proc(void) ...@@ -648,10 +652,11 @@ rpc_proc(void)
void void
rpc_unix_start(void) rpc_unix_start(void)
{ {
/*! · /*!
Fork RPC process · Fork RPC process
@return Returns -1 on error · @return Returns -1 on error
*/ · */
struct ProcChild *p; struct ProcChild *p;
p = proc_fork(rpc_proc, "ComarRPC"); p = proc_fork(rpc_proc, "ComarRPC");
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
unsigned char * unsigned char *
load_file(const char *fname, int *sizeptr) load_file(const char *fname, int *sizeptr)
{ {
/*! · /*!
Gets file size from stat and allocates enough memory to save file content. \n · Gets file size from stat and allocates enough memory to save file content. \n
sizeptr was used while loading compiled form of these scripts to python · sizeptr was used while loading compiled form of these scripts to python
@return Returns data loaded, or NULL on error · @return Returns data loaded, or NULL on error
*/ · */
FILE *f; FILE *f;
struct stat fs; struct stat fs;
...@@ -56,11 +56,11 @@ load_file(const char *fname, int *sizeptr) ...@@ -56,11 +56,11 @@ load_file(const char *fname, int *sizeptr)
int int
save_file(const char *fname, const char *buffer, size_t size) save_file(const char *fname, const char *buffer, size_t size)
{ {
/*! · /*!
@return Returns -1 if file could not be opened for binary writing \n · @return Returns -1 if file could not be opened for binary writing \n
Returns -2 if file could not be written to disc or buffer is empty \n · Returns -2 if file could not be written to disc or buffer is empty \n
Returns 0 on success · Returns 0 on success
*/ · */
FILE *f; FILE *f;
...@@ -78,11 +78,11 @@ save_file(const char *fname, const char *buffer, size_t size) ...@@ -78,11 +78,11 @@ save_file(const char *fname, const char *buffer, size_t size)
int int
utf8_is_valid(const char *str, size_t size) utf8_is_valid(const char *str, size_t size)
{ {
/*! · /*!
Because not all byte strings are valid, checks every character in string for security reasons · Because not all byte strings are valid, checks every character in string for security reasons
i.e for invalid utf8 string 0xC0 0x80 .. · i.e for invalid utf8 string 0xC0 0x80 ..
@return Returns 1 if is valid, 0 otherwise · @return Returns 1 if is valid, 0 otherwise
*/ · */
int i; int i;
int len = 0; int len = 0;
...@@ -96,6 +96,7 @@ utf8_is_valid(const char *str, size_t size) ...@@ -96,6 +96,7 @@ utf8_is_valid(const char *str, size_t size)
// those are not allowed at any point // those are not allowed at any point
if (0 == c || 0xFE == c || 0xFF == c) return 0; if (0 == c || 0xFE == c || 0xFF == c) return 0;
if (max) { if (max) {
// we are in a multi byte char // we are in a multi byte char
...@@ -153,12 +154,13 @@ time_diff(struct timeval *start, struct timeval *end) ...@@ -153,12 +154,13 @@ time_diff(struct timeval *start, struct timeval *end)
struct pack * struct pack *
pack_new(size_t min_size) pack_new(size_t min_size)
{ {
/*! · /*!
This function creates a pack struct ( described in utility.h ) · This function creates a pack struct ( described in utility.h )
which has a buffer of minimum size of 256 ( or min_size, if is bigger than 256 ) · which has a buffer of minimum size of 256 ( or min_size, if is bigger than 256 )
@return Returns created pack · @return Returns created pack
\sa utility.h · \sa utility.h
*/ · */
struct pack *p; struct pack *p;
p = calloc(sizeof(struct pack), 1); p = calloc(sizeof(struct pack), 1);
...@@ -177,10 +179,11 @@ pack_new(size_t min_size) ...@@ -177,10 +179,11 @@ pack_new(size_t min_size)
struct pack * struct pack *
pack_wrap(char *buffer, size_t size) pack_wrap(char *buffer, size_t size)
{ {
/*! · /*!
puts buffer in a pack and returns a pointer to pack, · puts buffer in a pack and returns a pointer to pack,
@return Returns Null on error, pointer to pack otherwise · @return Returns Null on error, pointer to pack otherwise
*/ · */
struct pack *p; struct pack *p;
p = calloc(sizeof(struct pack), 1); p = calloc(sizeof(struct pack), 1);
...@@ -191,11 +194,12 @@ pack_wrap(char *buffer, size_t size) ...@@ -191,11 +194,12 @@ pack_wrap(char *buffer, size_t size)
return p; return p;
} }
//! Duplicate a pack //! duplicate a pack
struct pack * struct pack *
pack_dup(struct pack *oldpak) pack_dup(struct pack *oldpak)
{ {
/*! @return Returns newly created pack */ /*! @return Returns newly created pack */
struct pack *p; struct pack *p;
p = calloc(sizeof(struct pack), 1); p = calloc(sizeof(struct pack), 1);
...@@ -262,11 +266,12 @@ pack_put(struct pack *p, const char *arg, size_t size) ...@@ -262,11 +266,12 @@ pack_put(struct pack *p, const char *arg, size_t size)
int int
pack_get(struct pack *p, char **argp, size_t *sizep) pack_get(struct pack *p, char **argp, size_t *sizep)
{ {
/*! · /*!
Writes p's size to sizep, if p is empty argp is set to NULL, else it is set to next data · Writes p's size to sizep, if p is empty argp is set to NULL, else it is set to next data
p's position is set to the end of data · p's position is set to the end of data
@return Returns 0 on error, 1 otherwise · @return Returns 0 on error, 1 otherwise
*/ · */
unsigned char *ptr; unsigned char *ptr;
size_t size; size_t size;
...@@ -285,12 +290,15 @@ pack_get(struct pack *p, char **argp, size_t *sizep) ...@@ -285,12 +290,15 @@ pack_get(struct pack *p, char **argp, size_t *sizep)
return 1; return 1;
} }
//! Replace a package. //! Replace a package
void void
pack_replace(struct pack *p, const char *arg, const char *value, size_t size) pack_replace(struct pack *p, const char *arg, const char *value, size_t size)
{ {
/*! Replaces a package with arg and value if it matches. · /*!
If it doesn't match, appends it as a new value */ Replaces a package with arg and value if it matches.
· If it doesn't match, appends it as a new value
*/
unsigned char *ptr; unsigned char *ptr;
char *t; char *t;
size_t ts; size_t ts;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment