Add ownership directives to overall omfile module config

This commit is contained in:
Nate Brown 2014-01-27 18:39:39 -08:00
parent 3e9346efc4
commit b41b86b009
2 changed files with 121 additions and 19 deletions

View File

@ -14,18 +14,81 @@
<p><b>Module Parameters</b>:</p>
<ul>
<li><strong>Template </strong>[templateName]<br>
Set the default template to be used if an action is not
configured to use a specific template.<br></li>
<li>
<strong>Template </strong>[templateName]<br>
Set the default template to be used if an action is not
configured to use a specific template.<br><br>
</li>
<li><strong>DirCreateMode </strong>[default 0700]<br>
Sets the default DirCreateMode to be used for an action
if no explicit one is specified.</br>
<li>
<strong>DirCreateMode </strong>[default 0700]<br>
Sets the default DirCreateMode to be used for an action
if no explicit one is specified.<br><br>
</li>
<li><strong>FileCreateMode </strong>[default 0644]<br>
Sets the default DirCreateMode to be used for an action
if no explicit one is specified.</br>
<li>
<strong>FileCreateMode </strong>[default 0644]<br>
Sets the default DirCreateMode to be used for an action
if no explicit one is specified.<br><br>
</li>
<li>
<strong>DirOwner </strong><br>
Set the default file owner for directories newly created. Please note that this setting does not affect the
owner of directories already existing. The parameter is a user name, for which the userid is obtained by
rsyslogd during startup processing. Interim changes to the user mapping are not detected.<br><br>
</li>
<li>
<strong>DirOwnerNum </strong><br>
Set the default file owner for directories newly created. Please note that this setting does not affect the
owner of directories already existing. The parameter is a numerical ID, which is used regardless of whether the
user actually exists. This can be useful if the user mapping is not available to rsyslog during startup.<br><br>
</li>
<li>
<strong>DirGroup </strong><br>
Set the default group for directories newly created. Please note that this setting does not affect the group of
directories already existing. The parameter is a group name, for which the groupid is obtained by rsyslogd on
during startup processing. Interim changes to the user mapping are not detected.<br><br>
</li>
<li>
<strong>DirGroupNum </strong><br>
Set the default group for directories newly created. Please note that this setting does not affect the group of
directories already existing. The parameter is a numerical ID, which is used regardless of whether the group
actually exists. This can be useful if the group mapping is not available to rsyslog during startup.<br><br>
</li>
<li>
<strong>FileOwner </strong><br>
Set the default file owner for files newly created. Please note that this setting does not affect the owner of
files already existing. The parameter is a user name, for which the userid is obtained by rsyslogd during
startup processing. Interim changes to the user mapping are not detected.<br><br>
</li>
<li>
<strong>FileOwnerNum </strong><br>
Set the default file owner for files newly created. Please note that this setting does not affect the owner of
files already existing. The parameter is a numerical ID, which which is used regardless of whether the user
actually exists. This can be useful if the user mapping is not available to rsyslog during startup.<br><br>
</li>
<li>
<strong>FileGroup </strong><br>
Set the default group for files newly created. Please note that this setting does not affect the group of files
already existing. The parameter is a group name, for which the groupid is obtained by rsyslogd during startup
processing. Interim changes to the user mapping are not detected.<br><br>
</li>
<li>
<strong>FileGroupNum </strong><br>
Set the default group for files newly created. Please note that this setting does not affect the group of files
already existing. The parameter is a numerical ID, which is used regardless of whether the group actually
exists. This can be useful if the group mapping is not available to rsyslog during startup.<br><br>
</li>
</ul>
<p>&nbsp;</p>
<p><b>Action Parameters</b>:</p>
<ul>
@ -153,10 +216,15 @@ unusable.
</ul>
<p><b>Sample:</b></p>
<p>The following command writes all syslog messages into a file.</p>
<textarea rows="5" cols="60">action(type="omfile"
DirCreateMode="0700"
FileCreateMode="0644"
File="/var/log/messages")
<textarea rows="10" cols="90">
# Set defaults for every output file
module(load="builtin:omfile" FileCreateMode="0644" DirCreateMode="0700" FileOwner="syslog")
# Output everything to /var/log/messages
*.* action(type="omfile" File="/var/log/messages")
# Output auth notices to /var/log/auth.log and only allow the owner to access it
auth,authpriv.* action(type="omfile" File="/var/log/auth.log" FileCreateMode="0600")
</textarea>
<br><br>

View File

@ -215,6 +215,10 @@ struct modConfData_s {
uchar *tplName; /* default template */
int fCreateMode; /* default mode to use when creating files */
int fDirCreateMode; /* default mode to use when creating files */
uid_t fileUID; /* default IDs for creation */
uid_t dirUID;
gid_t fileGID;
gid_t dirGID;
};
static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
@ -225,7 +229,15 @@ static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current ex
static struct cnfparamdescr modpdescr[] = {
{ "template", eCmdHdlrGetWord, 0 },
{ "dircreatemode", eCmdHdlrFileCreateMode, 0 },
{ "filecreatemode", eCmdHdlrFileCreateMode, 0 }
{ "filecreatemode", eCmdHdlrFileCreateMode, 0 },
{ "dirowner", eCmdHdlrUID, 0 },
{ "dirownernum", eCmdHdlrInt, 0 },
{ "dirgroup", eCmdHdlrGID, 0 },
{ "dirgroupnum", eCmdHdlrInt, 0 },
{ "fileowner", eCmdHdlrUID, 0 },
{ "fileownernum", eCmdHdlrInt, 0 },
{ "filegroup", eCmdHdlrGID, 0 },
{ "filegroupnum", eCmdHdlrInt, 0 },
};
static struct cnfparamblk modpblk =
{ CNFPARAMBLK_VERSION,
@ -832,6 +844,10 @@ CODESTARTbeginCnfLoad
pModConf->tplName = NULL;
pModConf->fCreateMode = 0644;
pModConf->fDirCreateMode = 0700;
pModConf->fileUID = -1;
pModConf->dirUID = -1;
pModConf->fileGID = -1;
pModConf->dirGID = -1;
ENDbeginCnfLoad
BEGINsetModCnf
@ -851,8 +867,10 @@ CODESTARTsetModCnf
}
for(i = 0 ; i < modpblk.nParams ; ++i) {
if(!pvals[i].bUsed)
if(!pvals[i].bUsed) {
continue;
}
if(!strcmp(modpblk.descr[i].name, "template")) {
loadModConf->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
if(pszFileDfltTplName != NULL) {
@ -864,6 +882,22 @@ CODESTARTsetModCnf
loadModConf->fDirCreateMode = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "filecreatemode")) {
loadModConf->fCreateMode = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "dirowner")) {
loadModConf->dirUID = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "dirownernum")) {
loadModConf->dirUID = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "dirgroup")) {
loadModConf->dirGID = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "dirgroupnum")) {
loadModConf->dirGID = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "fileowner")) {
loadModConf->fileUID = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "fileownernum")) {
loadModConf->fileUID = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "filegroup")) {
loadModConf->fileGID = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "filegroupnum")) {
loadModConf->fileGID = (int) pvals[i].val.d.n;
} else {
dbgprintf("omfile: program error, non-handled "
"param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
@ -978,10 +1012,10 @@ setInstParamDefaults(instanceData *__restrict__ const pData)
{
pData->fname = NULL;
pData->tplName = NULL;
pData->fileUID = -1;
pData->fileGID = -1;
pData->dirUID = -1;
pData->dirGID = -1;
pData->fileUID = loadModConf->fileUID;
pData->fileGID = loadModConf->fileGID;
pData->dirUID = loadModConf->dirUID;
pData->dirGID = loadModConf->dirGID;
pData->bFailOnChown = 1;
pData->iDynaFileCacheSize = 10;
pData->fCreateMode = loadModConf->fCreateMode;