summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--grammar/rainerscript.c3
-rw-r--r--plugins/imuxsock/imuxsock.c39
-rw-r--r--runtime/msg.c18
-rw-r--r--template.c26
4 files changed, 48 insertions, 38 deletions
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index d9812fee..2d5bbd9b 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -138,7 +138,7 @@ objlstDestruct(struct objlst *lst)
while(lst != NULL) {
toDel = lst;
lst = lst->next;
- // TODO: delete object
+ cnfobjDestruct(toDel->obj);
free(toDel);
}
}
@@ -647,6 +647,7 @@ cnfobjDestruct(struct cnfobj *o)
{
if(o != NULL) {
nvlstDestruct(o->nvlst);
+ objlstDestruct(o->subobjs);
free(o);
}
}
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
index 7eb3496f..61ce857c 100644
--- a/plugins/imuxsock/imuxsock.c
+++ b/plugins/imuxsock/imuxsock.c
@@ -641,14 +641,12 @@ getTrustedProp(struct ucred *cred, char *propName, uchar *buf, size_t lenBuf, in
if((fd = open(namebuf, O_RDONLY)) == -1) {
DBGPRINTF("error reading '%s'\n", namebuf);
- *lenProp = 0;
- FINALIZE;
+ ABORT_FINALIZE(RS_RET_ERR);
}
if((lenRead = read(fd, buf, lenBuf - 1)) == -1) {
DBGPRINTF("error reading file data for '%s'\n", namebuf);
- *lenProp = 0;
close(fd);
- FINALIZE;
+ ABORT_FINALIZE(RS_RET_ERR);
}
/* we strip after the first \n */
@@ -684,8 +682,7 @@ getTrustedExe(struct ucred *cred, uchar *buf, size_t lenBuf, int* lenProp)
if((lenRead = readlink(namebuf, (char*)buf, lenBuf - 1)) == -1) {
DBGPRINTF("error reading link '%s'\n", namebuf);
- *lenProp = 0;
- FINALIZE;
+ ABORT_FINALIZE(RS_RET_ERR);
}
buf[lenRead] = '\0';
@@ -820,15 +817,18 @@ SubmitMsg(uchar *pRcv, int lenRcv, lstn_t *pLstn, struct ucred *cred, struct tim
json_object_object_add(json, "uid", jval);
jval = json_object_new_int(cred->gid);
json_object_object_add(json, "gid", jval);
- getTrustedProp(cred, "comm", propBuf, sizeof(propBuf), &lenProp);
- jval = json_object_new_string((char*)propBuf);
- json_object_object_add(json, "appname", jval);
- getTrustedExe(cred, propBuf, sizeof(propBuf), &lenProp);
- jval = json_object_new_string((char*)propBuf);
- json_object_object_add(json, "exe", jval);
- getTrustedProp(cred, "cmdline", propBuf, sizeof(propBuf), &lenProp);
- jval = json_object_new_string((char*)propBuf);
- json_object_object_add(json, "cmd", jval);
+ if(getTrustedProp(cred, "comm", propBuf, sizeof(propBuf), &lenProp) == RS_RET_OK) {
+ jval = json_object_new_string((char*)propBuf);
+ json_object_object_add(json, "appname", jval);
+ }
+ if(getTrustedExe(cred, propBuf, sizeof(propBuf), &lenProp) == RS_RET_OK) {
+ jval = json_object_new_string((char*)propBuf);
+ json_object_object_add(json, "exe", jval);
+ }
+ if(getTrustedProp(cred, "cmdline", propBuf, sizeof(propBuf), &lenProp) == RS_RET_OK) {
+ jval = json_object_new_string((char*)propBuf);
+ json_object_object_add(json, "cmd", jval);
+ }
} else {
memcpy(pmsgbuf, pRcv, lenRcv);
memcpy(pmsgbuf+lenRcv, " @[", 3);
@@ -839,20 +839,17 @@ SubmitMsg(uchar *pRcv, int lenRcv, lstn_t *pLstn, struct ucred *cred, struct tim
memcpy(pmsgbuf+toffs, propBuf, lenProp);
toffs = toffs + lenProp;
- getTrustedProp(cred, "comm", propBuf, sizeof(propBuf), &lenProp);
- if(lenProp) {
+ if(getTrustedProp(cred, "comm", propBuf, sizeof(propBuf), &lenProp) == RS_RET_OK) {
memcpy(pmsgbuf+toffs, " _COMM=", 7);
memcpy(pmsgbuf+toffs+7, propBuf, lenProp);
toffs = toffs + 7 + lenProp;
}
- getTrustedExe(cred, propBuf, sizeof(propBuf), &lenProp);
- if(lenProp) {
+ if(getTrustedExe(cred, propBuf, sizeof(propBuf), &lenProp) == RS_RET_OK) {
memcpy(pmsgbuf+toffs, " _EXE=", 6);
memcpy(pmsgbuf+toffs+6, propBuf, lenProp);
toffs = toffs + 6 + lenProp;
}
- getTrustedProp(cred, "cmdline", propBuf, sizeof(propBuf), &lenProp);
- if(lenProp) {
+ if(getTrustedProp(cred, "cmdline", propBuf, sizeof(propBuf), &lenProp) == RS_RET_OK) {
memcpy(pmsgbuf+toffs, " _CMDLINE=", 9);
toffs = toffs + 9 +
copyescaped(pmsgbuf+toffs+9, propBuf, lenProp);
diff --git a/runtime/msg.c b/runtime/msg.c
index a89a01d2..afc79042 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -2420,16 +2420,20 @@ getCEEPropVal(msg_t *pM, es_str_t *propName, uchar **pRes, int *buflen, unsigned
if(*pbMustBeFreed)
free(*pRes);
*pRes = NULL;
-dbgprintf("AAAA: enter getCEEProp\n");
+dbgprintf("AAAA: enter getCEEPropVal\n");
// TODO: mutex?
if(pM->json == NULL) goto finalize_it;
- name = (uchar*)es_str2cstr(propName, NULL);
+ if(!es_strbufcmp(propName, (uchar*)"!", 1)) {
+ field = pM->json;
+ } else {
+ name = (uchar*)es_str2cstr(propName, NULL);
dbgprintf("AAAA: name to search '%s'\n", name);
- leaf = jsonPathGetLeaf(name, ustrlen(name));
+ leaf = jsonPathGetLeaf(name, ustrlen(name));
dbgprintf("AAAA: leaf '%s'\n", leaf);
- CHKiRet(jsonPathFindParent(pM, name, leaf, &parent, 1));
- field = json_object_object_get(parent, (char*)leaf);
+ CHKiRet(jsonPathFindParent(pM, name, leaf, &parent, 1));
+ field = json_object_object_get(parent, (char*)leaf);
+ }
*pRes = (uchar*) strdup(json_object_get_string(field));
dbgprintf("AAAA: json_object_get_string() returns '%s'\n", *pRes);
*buflen = (int) ustrlen(*pRes);
@@ -2462,6 +2466,10 @@ dbgprintf("AAAA: enter getCEEPropJSON\n");
ABORT_FINALIZE(RS_RET_NOT_FOUND);
}
+ if(!es_strbufcmp(propName, (uchar*)"!", 1)) {
+ *pjson = pM->json;
+ FINALIZE;
+ }
name = (uchar*)es_str2cstr(propName, NULL);
dbgprintf("AAAA: name to search '%s'\n", name);
leaf = jsonPathGetLeaf(name, ustrlen(name));
diff --git a/template.c b/template.c
index 6bcca42b..3cef586c 100644
--- a/template.c
+++ b/template.c
@@ -303,18 +303,13 @@ rsRetVal tplToJSON(struct template *pTpl, msg_t *pMsg, struct json_object **pjso
if(pTpe->data.field.propid == PROP_CEE) {
localRet = msgGetCEEPropJSON(pMsg, pTpe->data.field.propName, &jsonf);
if(localRet == RS_RET_OK) {
- json_object_object_add(json, (char*)pTpe->fieldName, jsonf);
+ json_object_object_add(json, (char*)pTpe->fieldName, json_object_get(jsonf));
} else {
DBGPRINTF("tplToJSON: error %d looking up property\n",
localRet);
-#if 0 /* TODO: as it looks, there currently is no way to define Null field values in json-c...
- we need to think how we will handle that.
- */
if(pTpe->data.field.options.bMandatory) {
- jsonf = json_object_new(json_type_null); //json_object_new_null();
- json_object_object_add(json, (char*)pTpe->fieldName, jsonf);
+ json_object_object_add(json, (char*)pTpe->fieldName, NULL);
}
-#endif
}
} else {
pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid,
@@ -1302,7 +1297,7 @@ static rsRetVal
createPropertyTpe(struct template *pTpl, struct cnfobj *o)
{
struct templateEntry *pTpe;
- cstr_t *name;
+ cstr_t *name = NULL;
uchar *outname = NULL;
int i;
int droplastlf = 0;
@@ -1333,9 +1328,12 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o)
if(!pvals[i].bUsed)
continue;
if(!strcmp(pblkProperty.descr[i].name, "name")) {
- rsCStrConstructFromszStr(&name,
- (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL));
+ char *tmp;
+
+ tmp = es_str2cstr(pvals[i].val.d.estr, NULL);
+ rsCStrConstructFromszStr(&name, (uchar*)tmp);
cstrFinalize(name);
+ free(tmp);
} else if(!strcmp(pblkProperty.descr[i].name, "droplastlf")) {
droplastlf = pvals[i].val.d.n;
} else if(!strcmp(pblkProperty.descr[i].name, "mandatory")) {
@@ -1542,7 +1540,7 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o)
pTpe->data.field.options.bSecPathReplace = 1;
break;
}
- pTpe->fieldName = ustrdup(outname);
+ pTpe->fieldName = outname;
if(outname != NULL)
pTpe->lenFieldName = ustrlen(outname);
pTpe->data.field.eDateFormat = datefmt;
@@ -1584,6 +1582,10 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o)
}
finalize_it:
+ if(pvals != NULL)
+ cnfparamvalsDestruct(pvals, &pblkProperty);
+ if(name != NULL)
+ rsCStrDestruct(&name);
RETiRet;
}
@@ -1767,6 +1769,8 @@ tplProcessCnf(struct cnfobj *o)
pTpl->optFormatEscape = JSON_ESCAPE;
finalize_it:
+ if(pvals != NULL)
+ cnfparamvalsDestruct(pvals, &pblk);
if(iRet != RS_RET_OK) {
if(pTpl != NULL) {
/* we simply make the template defunct in this case by setting