-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the functionality of Preserved Comments in cupsd.conf when cups… #640
base: master
Are you sure you want to change the base?
Changes from 7 commits
4d13be6
b9c57d1
ccf71a9
d999b0d
1c0ae05
d08c54f
0a6b3b3
d351867
d92236a
f241386
952fd3f
7470d73
d9c1986
04b6730
07e9450
5150a47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -698,7 +698,7 @@ cupsAdminSetServerSettings( | |
if (server_port <= 0) | ||
server_port = IPP_PORT; | ||
|
||
while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum)) | ||
while (_cupsFileGetConfAndComments(cupsd, line, sizeof(line), &value, &linenum)) | ||
{ | ||
if ((!_cups_strcasecmp(line, "Port") || !_cups_strcasecmp(line, "Listen")) && | ||
(remote_admin >= 0 || remote_any >= 0 || share_printers >= 0)) | ||
|
@@ -709,13 +709,10 @@ cupsAdminSetServerSettings( | |
|
||
if (remote_admin > 0 || remote_any > 0 || share_printers > 0) | ||
{ | ||
cupsFilePuts(temp, "# Allow remote access\n"); | ||
cupsFilePrintf(temp, "Port %d\n", server_port); | ||
} | ||
else | ||
{ | ||
cupsFilePuts(temp, "# Only listen for connections from the local " | ||
"machine.\n"); | ||
cupsFilePrintf(temp, "Listen localhost:%d\n", server_port); | ||
} | ||
|
||
|
@@ -749,7 +746,6 @@ cupsAdminSetServerSettings( | |
localp = cupsGetOption("BrowseLocalProtocols", cupsd_num_settings, | ||
cupsd_settings); | ||
|
||
cupsFilePuts(temp, "# Share local printers on the local network.\n"); | ||
cupsFilePuts(temp, "Browsing On\n"); | ||
|
||
if (!localp) | ||
|
@@ -763,7 +759,6 @@ cupsAdminSetServerSettings( | |
} | ||
else | ||
{ | ||
cupsFilePuts(temp, "# Disable printer sharing.\n"); | ||
cupsFilePuts(temp, "Browsing Off\n"); | ||
} | ||
} | ||
|
@@ -774,13 +769,10 @@ cupsAdminSetServerSettings( | |
|
||
if (debug_logging) | ||
{ | ||
cupsFilePuts(temp, | ||
"# Show troubleshooting information in error_log.\n"); | ||
cupsFilePuts(temp, "LogLevel debug\n"); | ||
} | ||
else | ||
{ | ||
cupsFilePuts(temp, "# Show general information in error_log.\n"); | ||
cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n"); | ||
} | ||
} | ||
|
@@ -800,8 +792,7 @@ cupsAdminSetServerSettings( | |
wrote_policy = 1; | ||
|
||
if (!user_cancel_any) | ||
cupsFilePuts(temp, " # Only the owner or an administrator can " | ||
"cancel a job...\n" | ||
cupsFilePuts(temp, | ||
" <Limit Cancel-Job>\n" | ||
" Order deny,allow\n" | ||
" Require user @OWNER " | ||
|
@@ -837,11 +828,6 @@ cupsAdminSetServerSettings( | |
{ | ||
wrote_admin_location = 1; | ||
|
||
if (remote_admin) | ||
cupsFilePuts(temp, " # Allow remote administration...\n"); | ||
else | ||
cupsFilePuts(temp, " # Restrict access to the admin pages...\n"); | ||
|
||
cupsFilePuts(temp, " Order allow,deny\n"); | ||
|
||
if (remote_admin) | ||
|
@@ -856,13 +842,6 @@ cupsAdminSetServerSettings( | |
{ | ||
wrote_conf_location = 1; | ||
|
||
if (remote_admin) | ||
cupsFilePuts(temp, " # Allow remote access to the configuration " | ||
"files...\n"); | ||
else | ||
cupsFilePuts(temp, " # Restrict access to the configuration " | ||
"files...\n"); | ||
|
||
cupsFilePuts(temp, " Order allow,deny\n"); | ||
|
||
if (remote_admin) | ||
|
@@ -877,13 +856,6 @@ cupsAdminSetServerSettings( | |
{ | ||
wrote_log_location = 1; | ||
|
||
if (remote_admin) | ||
cupsFilePuts(temp, " # Allow remote access to the log " | ||
"files...\n"); | ||
else | ||
cupsFilePuts(temp, " # Restrict access to the log " | ||
"files...\n"); | ||
|
||
cupsFilePuts(temp, " Order allow,deny\n"); | ||
|
||
if (remote_admin) | ||
|
@@ -899,18 +871,6 @@ cupsAdminSetServerSettings( | |
{ | ||
wrote_root_location = 1; | ||
|
||
if (remote_admin > 0 && share_printers > 0) | ||
cupsFilePuts(temp, " # Allow shared printing and remote " | ||
"administration...\n"); | ||
else if (remote_admin > 0) | ||
cupsFilePuts(temp, " # Allow remote administration...\n"); | ||
else if (share_printers > 0) | ||
cupsFilePuts(temp, " # Allow shared printing...\n"); | ||
else if (remote_any > 0) | ||
cupsFilePuts(temp, " # Allow remote access...\n"); | ||
else | ||
cupsFilePuts(temp, " # Restrict access to the server...\n"); | ||
|
||
cupsFilePuts(temp, " Order allow,deny\n"); | ||
|
||
if (remote_admin > 0 || remote_any > 0 || share_printers > 0) | ||
|
@@ -991,8 +951,7 @@ cupsAdminSetServerSettings( | |
wrote_policy = 1; | ||
|
||
if (!user_cancel_any) | ||
cupsFilePuts(temp, " # Only the owner or an administrator can cancel " | ||
"a job...\n" | ||
cupsFilePuts(temp, | ||
" <Limit Cancel-Job>\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this into the previous line. |
||
" Order deny,allow\n" | ||
" Require user @OWNER " | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#include "debug-internal.h" | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <stdbool.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for bool. |
||
|
||
# ifdef HAVE_LIBZ | ||
# include <zlib.h> | ||
|
@@ -335,6 +336,131 @@ _cupsFileCheckFilter( | |
#endif /* !_WIN32 */ | ||
|
||
|
||
/* | ||
* 'cupsFileGetConfAndComments()' - Get line and comments from a configuration file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name in the comment doesn't match with the function definition. |
||
*/ | ||
|
||
char * /* O - Line read or @code NULL@ on end of file or error */ | ||
_cupsFileGetConfAndComments(cups_file_t *fp, /* I - CUPS file */ | ||
char *buf, /* O - String buffer */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According DEVELOPING.md file every 8 spaces have to be a tab - please reflect that in the new code. I'll mark every place where there is a problem. |
||
size_t buflen, /* I - Size of string buffer */ | ||
char **value, /* O - Pointer to value */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use tab instead of every 8 spaces here. |
||
int *linenum) /* IO - Current line number */ | ||
{ | ||
char *ptr; /* Pointer into line */ | ||
|
||
|
||
/* | ||
* Range check input... | ||
*/ | ||
|
||
DEBUG_printf(("2cupsFileGetConfAndComments(fp=%p, buf=%p, buflen=" CUPS_LLFMT | ||
", value=%p, linenum=%p)", (void *)fp, (void *)buf, CUPS_LLCAST buflen, (void *)value, (void *)linenum)); | ||
zdohnal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!fp || (fp->mode != 'r' && fp->mode != 's') || | ||
!buf || buflen < 2 || !value) | ||
{ | ||
if (value) | ||
*value = NULL; | ||
|
||
return (NULL); | ||
} | ||
|
||
/* | ||
* Read the next line... | ||
*/ | ||
|
||
*value = NULL; | ||
|
||
while (cupsFileGets(fp, buf, buflen)) | ||
{ | ||
(*linenum) ++; | ||
|
||
/* | ||
zdohnal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Strip the comment from inline comment... | ||
*/ | ||
if ((ptr = strchr(buf, '#')) != NULL) | ||
{ | ||
int index = (int) (ptr - buf); | ||
for(int i=index-1; i>=0; i--) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code style issues (spaces) |
||
if (!_cups_isspace(buf[i])) | ||
{ | ||
buf[index] = '\0'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should put NULL terminator instead of last whitespace in this case. |
||
break; | ||
} | ||
} | ||
|
||
/* | ||
* Strip leading whitespace... | ||
*/ | ||
|
||
for (ptr = buf; _cups_isspace(*ptr); ptr ++); | ||
|
||
if (ptr > buf) | ||
_cups_strcpy(buf, ptr); | ||
|
||
zdohnal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* | ||
* See if there is anything left... | ||
*/ | ||
|
||
if (buf[0] != '#') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to check whether there is anything in the buffer, and if so, check for # - this big if-else block is unnecessary and add unnecessary indentation - the good practice is to not nest the code too much, the code should be as straight as possible.
|
||
{ | ||
/* | ||
* Yes, grab any value and return... | ||
*/ | ||
|
||
for (ptr = buf; *ptr; ptr ++) | ||
if (_cups_isspace(*ptr)) | ||
break; | ||
|
||
if (*ptr) | ||
{ | ||
/* | ||
* Have a value, skip any other spaces... | ||
*/ | ||
|
||
while (_cups_isspace(*ptr)) | ||
*ptr++ = '\0'; | ||
|
||
if (*ptr) | ||
*value = ptr; | ||
|
||
/* | ||
* Strip trailing whitespace and > for lines that begin with <... | ||
*/ | ||
|
||
ptr += strlen(ptr) - 1; | ||
|
||
if (buf[0] == '<' && *ptr == '>') | ||
*ptr-- = '\0'; | ||
else if (buf[0] == '<' && *ptr != '>') | ||
{ | ||
/* | ||
* Syntax error... | ||
*/ | ||
|
||
*value = NULL; | ||
return (buf); | ||
} | ||
|
||
while (ptr > *value && _cups_isspace(*ptr)) | ||
*ptr-- = '\0'; | ||
} | ||
|
||
/* | ||
* Return the line... | ||
*/ | ||
|
||
return (buf); | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The snippet I've provided in the previous review was pseudocode - not actual code which you can put into the code and have it done, but a code which is supposed to express an idea and has to be adjusted for actual source code. |
||
return (buf); | ||
} | ||
|
||
return (NULL); | ||
} | ||
|
||
|
||
/* | ||
* 'cupsFileClose()' - Close a CUPS file. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this into the previous line.