* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define RCSID "$Id: options.c,v 1.98 2005/07/13 12:31:36 paulus Exp $"
+#define RCSID "$Id: options.c,v 1.102 2008/06/15 06:53:06 paulus Exp $"
#include <ctype.h>
#include <stdio.h>
option_t *opt;
int oldpriv, n;
char *oldsource;
+ uid_t euid;
char *argv[MAXARGS];
char args[MAXARGS][MAXWORDLEN];
char cmd[MAXWORDLEN];
- if (check_prot)
- seteuid(getuid());
+ euid = geteuid();
+ if (check_prot && seteuid(getuid()) == -1) {
+ option_error("unable to drop privileges to open %s: %m", filename);
+ return 0;
+ }
f = fopen(filename, "r");
err = errno;
- if (check_prot)
- seteuid(0);
+ if (check_prot && seteuid(euid) == -1)
+ fatal("unable to regain privileges");
if (f == NULL) {
errno = err;
if (!must_exist) {
if (!(*parser)(argv))
return 0;
if (opt->flags & OPT_A2LIST) {
- struct option_value *ovp, **pp;
+ struct option_value *ovp, *pp;
ovp = malloc(sizeof(*ovp) + strlen(*argv));
if (ovp != 0) {
strcpy(ovp->value, *argv);
ovp->source = option_source;
ovp->next = NULL;
- pp = (struct option_value **) &opt->addr2;
- while (*pp != 0)
- pp = &(*pp)->next;
- *pp = ovp;
+ if (opt->addr2 == NULL) {
+ opt->addr2 = ovp;
+ } else {
+ for (pp = opt->addr2; pp->next != NULL; pp = pp->next)
+ ;
+ pp->next = ovp;
+ }
}
}
break;
break;
}
+ /*
+ * If addr2 wasn't used by any flag (OPT_A2COPY, etc.) but is set,
+ * treat it as a bool and set/clear it based on the OPT_A2CLR bit.
+ */
if (opt->addr2 && (opt->flags & (OPT_A2COPY|OPT_ENABLE
|OPT_A2PRINTER|OPT_A2STRVAL|OPT_A2LIST|OPT_A2OR)) == 0)
*(bool *)(opt->addr2) = !(opt->flags & OPT_A2CLR);
char **argv;
{
int fd, err;
+ uid_t euid;
- if (!privileged_option)
- seteuid(getuid());
+ euid = geteuid();
+ if (!privileged_option && seteuid(getuid()) == -1) {
+ option_error("unable to drop permissions to open %s: %m", *argv);
+ return 0;
+ }
fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
if (fd < 0 && errno == EEXIST)
fd = open(*argv, O_WRONLY | O_APPEND);
err = errno;
- if (!privileged_option)
- seteuid(0);
+ if (!privileged_option && seteuid(euid) == -1)
+ fatal("unable to regain privileges: %m");
if (fd < 0) {
errno = err;
option_error("Can't open log file %s: %m", *argv);