|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* zMaster daemon: a server for a zOffice verification.
|
|
|
|
* Secure Network Transport Layer Library implementation.
|
|
|
|
* This is a proprietary software. See COPYING for further details.
|
|
|
|
* This is a proprietary software. See COPYING for further details.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* (c) 2013-2014 Copyright Askele, inc. <http://askele.com>
|
|
|
|
* (c) 2013-2014 Copyright Askele, inc. <http://askele.com>
|
|
|
@ -172,14 +172,14 @@ static void __destroy_rpc_list_tree(usrtc_t *tree)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
usrtc_node_t *node;
|
|
|
|
usrtc_node_t *node;
|
|
|
|
cx_rpc_t *ent;
|
|
|
|
cx_rpc_t *ent;
|
|
|
|
|
|
|
|
|
|
|
|
for(node = usrtc_first(tree); node != NULL; node = usrtc_first(tree)) {
|
|
|
|
for(node = usrtc_first(tree); node != NULL; node = usrtc_first(tree)) {
|
|
|
|
ent = (cx_rpc_t *)usrtc_node_getdata(node);
|
|
|
|
ent = (cx_rpc_t *)usrtc_node_getdata(node);
|
|
|
|
usrtc_delete(tree, node);
|
|
|
|
usrtc_delete(tree, node);
|
|
|
|
free(ent->name);
|
|
|
|
free(ent->name);
|
|
|
|
free(ent);
|
|
|
|
free(ent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -187,18 +187,18 @@ static int __insert_rpc_function(usrtc_t *tree, const char *name, int (*rpcf)(vo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cx_rpc_t *ent = malloc(sizeof(cx_rpc_t));
|
|
|
|
cx_rpc_t *ent = malloc(sizeof(cx_rpc_t));
|
|
|
|
usrtc_node_t *node;
|
|
|
|
usrtc_node_t *node;
|
|
|
|
|
|
|
|
|
|
|
|
if(!ent) return ENOMEM;
|
|
|
|
if(!ent) return ENOMEM;
|
|
|
|
else node = &ent->node;
|
|
|
|
else node = &ent->node;
|
|
|
|
|
|
|
|
|
|
|
|
if(!(ent->name = strdup(name))) {
|
|
|
|
if(!(ent->name = strdup(name))) {
|
|
|
|
free(ent);
|
|
|
|
free(ent);
|
|
|
|
return ENOMEM;
|
|
|
|
return ENOMEM;
|
|
|
|
} else ent->rpcf = rpcf;
|
|
|
|
} else ent->rpcf = rpcf;
|
|
|
|
|
|
|
|
|
|
|
|
usrtc_node_init(node, ent);
|
|
|
|
usrtc_node_init(node, ent);
|
|
|
|
usrtc_insert(tree, node, ent->name);
|
|
|
|
usrtc_insert(tree, node, ent->name);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -210,7 +210,7 @@ static int __default_auth_set_context(void *cctx, sexp_t *sx)
|
|
|
|
int llen, idx, err;
|
|
|
|
int llen, idx, err;
|
|
|
|
|
|
|
|
|
|
|
|
//co->pctx = malloc(sizeof(perm_ctx_t));
|
|
|
|
//co->pctx = malloc(sizeof(perm_ctx_t));
|
|
|
|
|
|
|
|
|
|
|
|
/* skip keyword itself */
|
|
|
|
/* skip keyword itself */
|
|
|
|
lsx = sx->list->next;
|
|
|
|
lsx = sx->list->next;
|
|
|
|
/* now we expect a list of lists */
|
|
|
|
/* now we expect a list of lists */
|
|
|
@ -228,14 +228,14 @@ static int __default_auth_set_context(void *cctx, sexp_t *sx)
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_BASIC)) {
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_BASIC)) {
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
} else val = sx_in->val;
|
|
|
|
} else val = sx_in->val;
|
|
|
|
|
|
|
|
|
|
|
|
if(sexp_list_length(sx_iter) < 2) continue; /* we will ignore it */
|
|
|
|
if(sexp_list_length(sx_iter) < 2) continue; /* we will ignore it */
|
|
|
|
|
|
|
|
|
|
|
|
sexp_list_cdr(sx_iter, &sx_in);
|
|
|
|
sexp_list_cdr(sx_iter, &sx_in);
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_DQUOTE)) {
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_DQUOTE)) {
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
} else var = sx_in->val;
|
|
|
|
} else var = sx_in->val;
|
|
|
|
|
|
|
|
|
|
|
|
/* ok, now we need to analyze parameters */
|
|
|
|
/* ok, now we need to analyze parameters */
|
|
|
|
if(!strcmp(val, ":user")) {
|
|
|
|
if(!strcmp(val, ":user")) {
|
|
|
|
co->pctx->login = strdup(var); /* FIXME: check */
|
|
|
|
co->pctx->login = strdup(var); /* FIXME: check */
|
|
|
@ -246,7 +246,7 @@ static int __default_auth_set_context(void *cctx, sexp_t *sx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else continue; /* ignore */
|
|
|
|
} else continue; /* ignore */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ok, now we need to fill security context */
|
|
|
|
/* ok, now we need to fill security context */
|
|
|
|
tbuf = malloc(2048);
|
|
|
|
tbuf = malloc(2048);
|
|
|
|
if(conn_sys->secure_check)
|
|
|
|
if(conn_sys->secure_check)
|
|
|
@ -260,12 +260,12 @@ static int __default_auth_set_context(void *cctx, sexp_t *sx)
|
|
|
|
if(err) {
|
|
|
|
if(err) {
|
|
|
|
snprintf(tbuf, 2048, "(auth-set-error (%d))", err);
|
|
|
|
snprintf(tbuf, 2048, "(auth-set-error (%d))", err);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
snprintf(tbuf, 2048, "(auth-set-attr (:attr %d)(:uid %ld)(:gid %ld))",
|
|
|
|
snprintf(tbuf, 2048, "(auth-set-attr (:attr %d)(:uid %ld)(:gid %ld))",
|
|
|
|
co->pctx->p_attr, co->pctx->uid, co->pctx->gid);
|
|
|
|
co->pctx->p_attr, co->pctx->uid, co->pctx->gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* we will send it */
|
|
|
|
/* we will send it */
|
|
|
|
SSL_write(co->ssl, tbuf, strlen(tbuf)+1); /* FIXME: check it */
|
|
|
|
SSL_write(co->ssl, tbuf, strlen(tbuf)+1); /* FIXME: check it */
|
|
|
|
|
|
|
|
|
|
|
|
free(tbuf);
|
|
|
|
free(tbuf);
|
|
|
|
return err;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -276,12 +276,12 @@ static int __default_auth_set_attr(void *cctx, sexp_t *sx)
|
|
|
|
char *val, *var;
|
|
|
|
char *val, *var;
|
|
|
|
sexp_t *lsx, *sx_iter, *sx_in;
|
|
|
|
sexp_t *lsx, *sx_iter, *sx_in;
|
|
|
|
int llen, idx;
|
|
|
|
int llen, idx;
|
|
|
|
|
|
|
|
|
|
|
|
/* skip keyword itself */
|
|
|
|
/* skip keyword itself */
|
|
|
|
lsx = sx->list->next;
|
|
|
|
lsx = sx->list->next;
|
|
|
|
/* now we expect a list of lists */
|
|
|
|
/* now we expect a list of lists */
|
|
|
|
if(lsx->ty != SEXP_LIST) {
|
|
|
|
if(lsx->ty != SEXP_LIST) {
|
|
|
|
printf("%s:%d\n", __FUNCTION__, __LINE__);
|
|
|
|
// printf("%s:%d\n", __FUNCTION__, __LINE__);
|
|
|
|
return EINVAL;
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* take length of the list */
|
|
|
|
/* take length of the list */
|
|
|
@ -294,15 +294,15 @@ static int __default_auth_set_attr(void *cctx, sexp_t *sx)
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_BASIC)) {
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_BASIC)) {
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
} else val = sx_in->val;
|
|
|
|
} else val = sx_in->val;
|
|
|
|
|
|
|
|
|
|
|
|
if(sexp_list_length(sx_iter) < 2) continue; /* we will ignore it */
|
|
|
|
if(sexp_list_length(sx_iter) < 2) continue; /* we will ignore it */
|
|
|
|
|
|
|
|
|
|
|
|
sexp_list_cdr(sx_iter, &sx_in);
|
|
|
|
sexp_list_cdr(sx_iter, &sx_in);
|
|
|
|
|
|
|
|
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_BASIC)) {
|
|
|
|
if(!SEXP_IS_TYPE(sx_in, SEXP_BASIC)) {
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
return EINVAL; /* TODO: return correct error code, clean up*/
|
|
|
|
} else var = sx_in->val;
|
|
|
|
} else var = sx_in->val;
|
|
|
|
|
|
|
|
|
|
|
|
/* ok, now we need to analyze parameters */
|
|
|
|
/* ok, now we need to analyze parameters */
|
|
|
|
if(!strcmp(val, ":attr")) {
|
|
|
|
if(!strcmp(val, ":attr")) {
|
|
|
|
co->pctx->p_attr = atoi(var);
|
|
|
|
co->pctx->p_attr = atoi(var);
|
|
|
@ -315,7 +315,7 @@ static int __default_auth_set_attr(void *cctx, sexp_t *sx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else continue; /* ignore */
|
|
|
|
} else continue; /* ignore */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -323,7 +323,7 @@ static int __default_auth_set_error(void *cctx, sexp_t *sx)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *errstr = NULL;
|
|
|
|
char *errstr = NULL;
|
|
|
|
int r;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
|
|
/* skip keyword itself */
|
|
|
|
/* skip keyword itself */
|
|
|
|
sx->list = sx->list->next;
|
|
|
|
sx->list = sx->list->next;
|
|
|
|
/* be sure - this is a list */
|
|
|
|
/* be sure - this is a list */
|
|
|
@ -331,7 +331,7 @@ static int __default_auth_set_error(void *cctx, sexp_t *sx)
|
|
|
|
else sx = sx->list; /* get it */
|
|
|
|
else sx = sx->list; /* get it */
|
|
|
|
errstr = sx->list->val;
|
|
|
|
errstr = sx->list->val;
|
|
|
|
r = atoi(errstr);
|
|
|
|
r = atoi(errstr);
|
|
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -342,7 +342,7 @@ static int __default_ch_get_types(void *cctx, sexp_t *sx)
|
|
|
|
rpc_typed_list_t *list_ent;
|
|
|
|
rpc_typed_list_t *list_ent;
|
|
|
|
char *tbuf = malloc(4096), *tt;
|
|
|
|
char *tbuf = malloc(4096), *tt;
|
|
|
|
int err = 0;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* if we cannot allocate anything ... */
|
|
|
|
/* if we cannot allocate anything ... */
|
|
|
|
if(!tbuf) return ENOMEM;
|
|
|
|
if(!tbuf) return ENOMEM;
|
|
|
|
/* ok here we go */
|
|
|
|
/* ok here we go */
|
|
|
@ -362,23 +362,22 @@ static int __default_ch_get_types(void *cctx, sexp_t *sx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
snprintf(tt, 4096, "))");
|
|
|
|
snprintf(tt, 4096, "))");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* reply to this rpc */
|
|
|
|
/* reply to this rpc */
|
|
|
|
SSL_write(co->ssl, tbuf, strlen(tbuf)+sizeof(char)); /* FIXME: do checks */
|
|
|
|
SSL_write(co->ssl, tbuf, strlen(tbuf)+sizeof(char)); /* FIXME: do checks */
|
|
|
|
|
|
|
|
|
|
|
|
free(tbuf);
|
|
|
|
free(tbuf);
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int __default_ch_set_types(void *cctx, sexp_t *sx)
|
|
|
|
static int __default_ch_set_types(void *cctx, sexp_t *sx)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
conn_t *co = (conn_t *)cctx;
|
|
|
|
conn_t *co = (conn_t *)cctx;
|
|
|
|
printf("setting types\n");
|
|
|
|
|
|
|
|
char buf[1024], *val, *var;
|
|
|
|
char buf[1024], *val, *var;
|
|
|
|
int r = 0, llen, typeid, idx;
|
|
|
|
int r = 0, llen, typeid, idx;
|
|
|
|
sexp_t *lsx, *sx_iter, *sx_in;
|
|
|
|
sexp_t *lsx, *sx_iter, *sx_in;
|
|
|
|
|
|
|
|
|
|
|
|
/* skip keyword itself */
|
|
|
|
/* skip keyword itself */
|
|
|
|
lsx = sx->list->next;
|
|
|
|
lsx = sx->list->next;
|
|
|
|
/* now we expect a list of lists */
|
|
|
|
/* now we expect a list of lists */
|
|
|
|