admserv/cgi-src40/config.c | 46 ++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
New commits:
commit 2d2a225b0a435e7f3199c4656ea2078b02cc6573
Author: Endi S. Dewata <edewata(a)redhat.com>
Date: Fri Apr 23 18:59:56 2010 -0500
Bug 368481 - Unable to change Admin Server log paths in Console
https://bugzilla.redhat.com/show_bug.cgi?id=368481
Resolves: bug 368481
Bug Description: Unable to change Admin Server log paths in Console
Fix Description: The console assumes that the attribute values read from
and written to the server will follow the same format, so the config.c
has been modified to accept the full path instead of just the file name.
The path will be validated to ensure that it is inside the server log
dir (ADMSERV_LOG_DIR). The return code of validate_logfile() has been
changed such that 0 indicates no error has occured.
Reviewed by: rmeggins (and pushed)
diff --git a/admserv/cgi-src40/config.c b/admserv/cgi-src40/config.c
index 886752f..8e04f88 100644
--- a/admserv/cgi-src40/config.c
+++ b/admserv/cgi-src40/config.c
@@ -541,7 +541,7 @@ int main(int argc, char *argv[])
/* Check if access log file is being changed */
if (strcasecmp(nameptr,"configuration.nsaccesslog") == 0) {
int rc = validate_logfile(logdir, valptr);
- if (rc == 2) {
+ if (rc == 1) {
/* report error */
psetDelete(pset);
if (i18nResource)
@@ -552,7 +552,7 @@ int main(int argc, char *argv[])
else PR_snprintf(error_info, sizeof(error_info), "%s log file name must be a
valid file name and must not include the path. [%s] is invalid.",
"Access", nameptr);
rpt_err(APP_ERROR, error_info, NULL, NULL);
- } else if (rc == 0) {
+ } else if (rc == 2) {
/* report error */
psetDelete(pset);
if (i18nResource)
@@ -565,8 +565,8 @@ int main(int argc, char *argv[])
rpt_err(APP_ERROR, error_info, NULL, NULL);
}
else {
- char *pathline = PR_smprintf("%s/%s %s", logdir, valptr,
"common");
- err = update_conf("console.conf", "CustomLog",
pathline);
+ char *pathline = PR_smprintf("%s %s", valptr, "common");
+ err = update_conf("console.conf", "CustomLog", pathline);
PR_smprintf_free(pathline);
}
}
@@ -574,7 +574,7 @@ int main(int argc, char *argv[])
/* Check if error log file is being changed */
if (strcasecmp(nameptr,"configuration.nserrorlog") == 0) {
int rc = validate_logfile(logdir, valptr);
- if (rc == 2) {
+ if (rc == 1) {
/* report error */
psetDelete(pset);
if (i18nResource)
@@ -585,7 +585,7 @@ int main(int argc, char *argv[])
else PR_snprintf(error_info, sizeof(error_info), "%s log file name must be a
valid file name and must not include the path. [%s] is invalid.",
"Error", nameptr);
rpt_err(APP_ERROR, error_info, NULL, NULL);
- } else if (rc == 0) {
+ } else if (rc == 2) {
/* report error */
psetDelete(pset);
if (i18nResource)
@@ -598,8 +598,7 @@ int main(int argc, char *argv[])
rpt_err(APP_ERROR, error_info, NULL, NULL);
}
else {
- char *newpath = PR_smprintf("%s/%s", logdir, valptr);
- err = update_conf("console.conf", "ErrorLog", newpath);
+ err = update_conf("console.conf", "ErrorLog", valptr);
}
}
@@ -1068,21 +1067,30 @@ static int validate_addr(char* ip) {
*/
static int validate_logfile(char *logdir, char *name) {
FILE *f;
- char *fullname;
+ char *filename;
+ int n;
- if (!name || !*name ||
- !util_is_valid_path_string(name)) {
- return 2; /* error */
+ if (!name || !*name) {
+ return 1; /* invalid path */
}
- fullname = PR_smprintf("%s/%s", logdir, name);
+ n = strlen(logdir);
- f = fopen(fullname, "a+");
- PR_smprintf_free(fullname);
- if (f != NULL) {
- fclose(f);
- return 1; /* ok*/
+ if (strncmp(logdir, name, n)) {
+ return 1; /* invalid path */
}
- return 0; /* error */
+ filename = &name[n+1];
+
+ if (!util_is_valid_path_string(filename)) {
+ return 1; /* invalid path */
+ }
+
+ f = fopen(name, "a+");
+ if (!f) {
+ return 2; /* can't open file */
+ }
+
+ fclose(f);
+ return 0; /* ok */
}