summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cfsysline.c46
-rw-r--r--cfsysline.h1
-rw-r--r--syslogd.c37
3 files changed, 49 insertions, 35 deletions
diff --git a/cfsysline.c b/cfsysline.c
index cfa8c3ee..8fb66d89 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -28,6 +28,7 @@
#include <assert.h>
#include <string.h>
#include <pwd.h>
+#include <grp.h>
#include "rsyslog.h"
#include "syslogd.h" /* TODO: when the module interface & library design is done, this should be able to go away */
@@ -76,6 +77,50 @@ static int doParseOnOffOption(uchar **pp)
}
+/* extract a groupname and return its gid.
+ * rgerhards, 2007-07-17
+ */
+rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
+{
+ struct group *pgBuf;
+ struct group gBuf;
+ rsRetVal iRet = RS_RET_OK;
+ uchar szName[256];
+ char stringBuf[2048]; /* I hope this is large enough... */
+
+ assert(pp != NULL);
+ assert(*pp != NULL);
+ assert(pVal != NULL);
+
+ if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) {
+ logerror("could not extract group name");
+ iRet = RS_RET_NOT_FOUND;
+ goto finalize_it;
+ }
+
+ getgrnam_r((char*)szName, &gBuf, stringBuf, sizeof(stringBuf), &pgBuf);
+
+ if(pgBuf == NULL) {
+ logerrorSz("ID for group '%s' could not be found or error", (char*)szName);
+ iRet = RS_RET_NOT_FOUND;
+ } else {
+ if(pSetHdlr == NULL) {
+ /* we should set value directly to var */
+ *((gid_t*)pVal) = pgBuf->gr_gid;
+ } else {
+ /* we set value via a set function */
+ pSetHdlr(pVal, pgBuf->gr_gid);
+ }
+ dprintf("gid %d obtained for group '%s'\n", pgBuf->gr_gid, szName);
+ }
+
+ skipWhiteSpace(pp); /* skip over any whitespace */
+
+finalize_it:
+ return iRet;
+}
+
+
/* extract a username and return its uid.
* rgerhards, 2007-07-17
*/
@@ -101,6 +146,7 @@ rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
if(ppwBuf == NULL) {
logerrorSz("ID for user '%s' could not be found or error", (char*)szName);
+ iRet = RS_RET_NOT_FOUND;
} else {
if(pSetHdlr == NULL) {
/* we should set value directly to var */
diff --git a/cfsysline.h b/cfsysline.h
index 78b2fec2..66d01bed 100644
--- a/cfsysline.h
+++ b/cfsysline.h
@@ -68,5 +68,6 @@ rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine);
/* the next ones go away later */
rsRetVal doBinaryOptionLine(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal);
rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
+rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
#endif /* #ifndef CFSYSLINE_H_INCLUDED */
diff --git a/syslogd.c b/syslogd.c
index 1d9d13d0..3743fa72 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -149,7 +149,6 @@
#include <string.h>
#include <stdarg.h>
#include <time.h>
-#include <grp.h>
#include <sys/syslog.h>
#include <sys/param.h>
@@ -3513,38 +3512,6 @@ static void doModLoad(uchar **pp)
}
-/* extract a groupname and return its gid.
- * rgerhards, 2007-07-17
- */
-static void doGetGID(uchar **pp, gid_t *pGid)
-{
- struct group *pgBuf;
- struct group gBuf;
- uchar szName[256];
- char stringBuf[2048]; /* I hope this is large enough... */
-
- assert(pp != NULL);
- assert(*pp != NULL);
- assert(pGid != NULL);
-
- if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) {
- logerror("could not extract group name");
- return;
- }
-
- getgrnam_r((char*)szName, &gBuf, stringBuf, sizeof(stringBuf), &pgBuf);
-
- if(pgBuf == NULL) {
- logerrorSz("ID for group '%s' could not be found or error", (char*)szName);
- } else {
- *pGid = pgBuf->gr_gid;
- dprintf("gid %d obtained for group '%s'\n", *pGid, szName);
- }
-
- skipWhiteSpace(pp); /* skip over any whitespace */
-}
-
-
/* parse the control character escape prefix and store it.
* added 2007-07-17 by rgerhards
*/
@@ -3731,11 +3698,11 @@ void cfsysline(uchar *p)
} else if(!strcasecmp((char*) szCmd, "dirowner")) {
doGetUID(&p, NULL, &dirUID);
} else if(!strcasecmp((char*) szCmd, "dirgroup")) {
- doGetGID(&p, &dirGID);
+ doGetGID(&p, NULL, &dirGID);
} else if(!strcasecmp((char*) szCmd, "fileowner")) {
doGetUID(&p, NULL, &fileUID);
} else if(!strcasecmp((char*) szCmd, "filegroup")) {
- doGetGID(&p, &fileGID);
+ doGetGID(&p, NULL, &fileGID);
} else if(!strcasecmp((char*) szCmd, "dynafilecachesize")) {
doDynaFileCacheSizeLine(&p);
} else if(!strcasecmp((char*) szCmd, "repeatedmsgreduction")) {