summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-07-17 13:16:44 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-07-17 13:16:44 +0000
commita768128281ea07a7f0b0a2ec773a40dbfecd1072 (patch)
tree1a4ae7f053dffe70f01338c6d4a35d3448387374
parent648370956683f65c8d60ba71ca158bf68d27db9a (diff)
downloadrsyslog-a768128281ea07a7f0b0a2ec773a40dbfecd1072.tar.gz
rsyslog-a768128281ea07a7f0b0a2ec773a40dbfecd1072.tar.xz
rsyslog-a768128281ea07a7f0b0a2ec773a40dbfecd1072.zip
added $FailOnChownFailure config parameter
-rw-r--r--ChangeLog1
-rwxr-xr-xsrUtils.c8
-rwxr-xr-xsrUtils.h2
-rw-r--r--syslogd-types.h4
-rw-r--r--syslogd.c38
5 files changed, 38 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 291b90d7..0bcfa9d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@ Version 1.16.1 (RGer), 2007-07-17
- added $FileGroup config parameter
- added $DirOwner config parameter
- added $DirGroup config parameter
+- added $FailOnChownFailure config parameter
- added regular expression support to the filter engine
thanks to Michel Samia for providing the patch!
- enhanced $AllowedSender functionality. Credits to mildew@gmail.com for
diff --git a/srUtils.c b/srUtils.c
index 2b819ca5..376a0d16 100755
--- a/srUtils.c
+++ b/srUtils.c
@@ -112,7 +112,7 @@ uchar *srUtilStrDup(uchar *pOld, size_t len)
* are to be created with.
*/
int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode,
- uid_t uid, gid_t gid)
+ uid_t uid, gid_t gid, int bFailOnChown)
{
uchar *p;
uchar *pszWork;
@@ -135,7 +135,11 @@ int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode,
if(uid != -1 || gid != -1) {
/* we need to set owner/group */
if(chown(pszWork, uid, gid) != 0)
- bErr = 1;
+ if(bFailOnChown)
+ bErr = 1;
+ /* silently ignore if configured
+ * to do so.
+ */
}
} else
bErr = 1;
diff --git a/srUtils.h b/srUtils.h
index cf679272..93f026ab 100755
--- a/srUtils.h
+++ b/srUtils.h
@@ -59,5 +59,5 @@ unsigned char *srUtilStrDup(unsigned char *pOld, size_t len);
* for it.
* added 2007-07-17 by rgerhards
*/
-int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode, uid_t uid, gid_t gid);
+int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode, uid_t uid, gid_t gid, int bFailOnChown);
#endif
diff --git a/syslogd-types.h b/syslogd-types.h
index a803fc08..c598f73d 100644
--- a/syslogd-types.h
+++ b/syslogd-types.h
@@ -257,6 +257,7 @@ struct filed {
uid_t dirUID;
gid_t fileGID;
gid_t dirGID;
+ int bFailOnChown; /* fail creation if chown fails? */
int iCurrElt; /* currently active cache element (-1 = none) */
int iCurrCacheSize; /* currently cache size (1-based) */
int iDynaFileCacheSize; /* size of file handle cache */
@@ -288,3 +289,6 @@ struct filed {
typedef struct filed selector_t; /* new type name */
#endif /* #ifndef SYSLOGD_TYPES_INCLUDED */
+/*
+ * vi:set ai:
+ */
diff --git a/syslogd.c b/syslogd.c
index d340ea44..e3ef541c 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -642,6 +642,7 @@ static struct code FacNames[] = {
/* global variables for config file state */
static int Debug; /* debug flag - read-only after startup */
+static int bFailOnChown; /* fail if chown fails? */
static uid_t fileUID; /* UID to be used for newly created files */
static uid_t fileGID; /* GID to be used for newly created files */
static uid_t dirUID; /* UID to be used for newly created directories */
@@ -724,6 +725,7 @@ static void resetConfigVariables(void)
fileGID = -1;
dirUID = -1;
dirGID = -1;
+ bFailOnChown = 1;
iDynaFileCacheSize = 10;
fCreateMode = 0644;
fDirCreateMode = 0644;
@@ -6273,7 +6275,7 @@ static int prepareDynFile(selector_t *f)
*/
if(makeFileParentDirs(newFileName, strlen(newFileName),
f->f_un.f_file.fDirCreateMode, f->f_un.f_file.dirUID,
- f->f_un.f_file.dirGID) == 0) {
+ f->f_un.f_file.dirGID, f->f_un.f_file.bFailOnChown) == 0) {
f->f_file = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
f->f_un.f_file.fCreateMode);
if(f->f_file != -1) {
@@ -6282,15 +6284,16 @@ static int prepareDynFile(selector_t *f)
/* we need to set owner/group */
if(fchown(f->f_file, f->f_un.f_file.fileUID,
f->f_un.f_file.fileGID) != 0) {
- /* we fail in this case - later we could
- * possibly control this via a user-defined
- * option.
- */
- int eSave = errno;
- close(f->f_file);
- f->f_file = -1;
- errno = eSave;
+ if(f->f_un.f_file.bFailOnChown) {
+ int eSave = errno;
+ close(f->f_file);
+ f->f_file = -1;
+ errno = eSave;
}
+ /* we will silently ignore the chown() failure
+ * if configured to do so.
+ */
+ }
}
}
}
@@ -7761,6 +7764,8 @@ void cfsysline(uchar *p)
doBinaryOptionLine(&p, &bCreateDirs);
} else if(!strcasecmp((char*) szCmd, "debugprinttemplatelist")) {
doBinaryOptionLine(&p, &bDebugPrintTemplateList);
+ } else if(!strcasecmp((char*) szCmd, "failonchownfailure")) {
+ doBinaryOptionLine(&p, &bFailOnChown);
} else if(!strcasecmp((char*) szCmd, "resetconfigvariables")) {
resetConfigVariables();
} else { /* invalid command! */
@@ -8096,11 +8101,19 @@ static void init()
case F_TTY:
case F_CONSOLE:
if(f->f_un.f_file.bDynamicName) {
- printf("[dynamic, template='%s', cache size=%d, "
- "create dirs=%d]",
+ printf("[dynamic]\n\ttemplate='%s'\n"
+ "\tfile cache size=%d\n"
+ "\tcreate directories: %s\n"
+ "\tfile owner %d, group %d\n"
+ "\tdirectory owner %d, group %d\n"
+ "\tfail if owner/group can not be set: %s\n",
f->f_un.f_file.f_fname,
f->f_un.f_file.iDynaFileCacheSize,
- f->f_un.f_file.bCreateDirs);
+ f->f_un.f_file.bCreateDirs ? "yes" : "no",
+ f->f_un.f_file.fileUID, f->f_un.f_file.fileGID,
+ f->f_un.f_file.dirUID, f->f_un.f_file.dirGID,
+ f->f_un.f_file.bFailOnChown ? "yes" : "no"
+ );
} else { /* regular file */
printf("%s", f->f_un.f_file.f_fname);
if (f->f_file == -1)
@@ -9030,6 +9043,7 @@ static rsRetVal cfline(char *line, register selector_t *f)
f->f_un.f_file.fCreateMode = fCreateMode; /* freeze current setting */
f->f_un.f_file.fDirCreateMode = fDirCreateMode; /* preserve current setting */
f->f_un.f_file.bCreateDirs = bCreateDirs;
+ f->f_un.f_file.bFailOnChown = bFailOnChown;
f->f_un.f_file.fileUID = fileUID;
f->f_un.f_file.fileGID = fileGID;
f->f_un.f_file.dirUID = dirUID;