summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/cron/misc.c')
-rw-r--r--usr.sbin/cron/misc.c162
1 files changed, 57 insertions, 105 deletions
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index f1cadbbb99d..55d1caef2e5 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.19 2002/05/28 02:03:01 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.20 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,20 +21,18 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: misc.c,v 1.19 2002/05/28 02:03:01 millert Exp $";
+static char const rcsid[] = "$OpenBSD: misc.c,v 1.20 2002/07/08 18:11:02 millert Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
* vix 30dec86 [written]
*/
-
#include "cron.h"
#include <sys/socket.h>
#include <sys/un.h>
-
-#if defined(LOG_CRON) && defined(LOG_FILE)
+#if defined(SYSLOG) && defined(LOG_FILE)
# undef LOG_FILE
#endif
@@ -42,8 +40,11 @@ static char rcsid[] = "$OpenBSD: misc.c,v 1.19 2002/05/28 02:03:01 millert Exp $
# define LOG_CRON LOG_DAEMON
#endif
+#ifndef FACILITY
+#define FACILITY LOG_CRON
+#endif
-static int LogFD = ERR;
+static int LogFD = ERR;
/*
* glue_strings is the overflow-safe equivalent of
@@ -53,12 +54,8 @@ static int LogFD = ERR;
* glue_strings fails.
*/
int
-glue_strings(buffer, buffer_size, a, b, separator)
- char *buffer;
- int buffer_size;
- char *a;
- char *b;
- int separator;
+glue_strings(char *buffer, size_t buffer_size, const char *a, const char *b,
+ char separator)
{
char *buf;
char *buf_end;
@@ -85,7 +82,7 @@ glue_strings(buffer, buffer_size, a, b, separator)
}
int
-strcmp_until(const char *left, const char *right, int until) {
+strcmp_until(const char *left, const char *right, char until) {
while (*left && *left != until && *left == *right) {
left++;
right++;
@@ -98,13 +95,10 @@ strcmp_until(const char *left, const char *right, int until) {
return (*left - *right);
}
-
/* strdtb(s) - delete trailing blanks in string 's' and return new length
*/
int
-strdtb(s)
- char *s;
-{
+strdtb(char *s) {
char *x = s;
/* scan forward to the null
@@ -129,11 +123,8 @@ strdtb(s)
return (x - s);
}
-
int
-set_debug_flags(flags)
- char *flags;
-{
+set_debug_flags(const char *flags) {
/* debug flags are of the form flag[,flag ...]
*
* if an error occurs, print a message to stdout and return FALSE.
@@ -147,7 +138,7 @@ set_debug_flags(flags)
#else /* DEBUGGING */
- char *pc = flags;
+ const char *pc = flags;
DebugFlags = 0;
@@ -157,11 +148,10 @@ set_debug_flags(flags)
/* try to find debug flag name in our list.
*/
- for ( test = DebugFlagNames, mask = 1;
- *test != NULL && strcmp_until(*test, pc, ',');
- test++, mask <<= 1
- )
- ;
+ for (test = DebugFlagNames, mask = 1;
+ *test != NULL && strcmp_until(*test, pc, ',');
+ test++, mask <<= 1)
+ continue;
if (!*test) {
fprintf(stderr,
@@ -181,7 +171,7 @@ set_debug_flags(flags)
}
if (DebugFlags) {
- int flag;
+ int flag;
fprintf(stderr, "debug flags enabled:");
@@ -196,10 +186,8 @@ set_debug_flags(flags)
#endif /* DEBUGGING */
}
-
void
-set_cron_uid()
-{
+set_cron_uid(void) {
#if defined(BSD) || defined(POSIX)
if (seteuid(ROOT_UID) < OK) {
perror("seteuid");
@@ -213,11 +201,9 @@ set_cron_uid()
#endif
}
-
void
-set_cron_cwd()
-{
- struct stat sb;
+set_cron_cwd(void) {
+ struct stat sb;
/* first check for CRONDIR ("/var/cron" or some such)
*/
@@ -232,7 +218,7 @@ set_cron_cwd()
exit(ERROR_EXIT);
}
}
- if (!(sb.st_mode & S_IFDIR)) {
+ if ((sb.st_mode & S_IFDIR) == 0) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
CRONDIR);
exit(ERROR_EXIT);
@@ -256,14 +242,13 @@ set_cron_cwd()
exit(ERROR_EXIT);
}
}
- if (!(sb.st_mode & S_IFDIR)) {
+ if ((sb.st_mode & S_IFDIR) == 0) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
SPOOL_DIR);
exit(ERROR_EXIT);
}
}
-
/* acquire_daemonlock() - write our PID into /etc/cron.pid, unless
* another daemon is already running, which we detect here.
*
@@ -272,15 +257,13 @@ set_cron_cwd()
* can rewrite our PID into the PIDFILE after the fork.
*/
void
-acquire_daemonlock(closeflag)
- int closeflag;
-{
- static int fd = -1;
- char buf[3*MAX_FNAME];
- char pidfile[MAX_FNAME];
- char *ep;
- long otherpid;
- ssize_t num;
+acquire_daemonlock(int closeflag) {
+ static int fd = -1;
+ char buf[3*MAX_FNAME];
+ char pidfile[MAX_FNAME];
+ char *ep;
+ long otherpid;
+ ssize_t num;
if (closeflag) {
/* close stashed fd for child so we don't leak it. */
@@ -346,10 +329,8 @@ acquire_daemonlock(closeflag)
/* get_char(file) : like getc() but increment LineNumber on newlines
*/
int
-get_char(file)
- FILE *file;
-{
- int ch;
+get_char(FILE *file) {
+ int ch;
ch = getc(file);
if (ch == '\n')
@@ -357,20 +338,15 @@ get_char(file)
return (ch);
}
-
/* unget_char(ch, file) : like ungetc but do LineNumber processing
*/
void
-unget_char(ch, file)
- int ch;
- FILE *file;
-{
+unget_char(int ch, FILE *file) {
ungetc(ch, file);
if (ch == '\n')
Set_LineNum(LineNumber - 1)
}
-
/* get_string(str, max, file, termstr) : like fgets() but
* (1) has terminator string which should include \n
* (2) will always leave room for the null
@@ -378,13 +354,8 @@ unget_char(ch, file)
* (4) returns EOF or terminating character, whichever
*/
int
-get_string(string, size, file, terms)
- char *string;
- int size;
- FILE *file;
- char *terms;
-{
- int ch;
+get_string(char *string, int size, FILE *file, char *terms) {
+ int ch;
while (EOF != (ch = get_char(file)) && !strchr(terms, ch)) {
if (size > 1) {
@@ -399,14 +370,11 @@ get_string(string, size, file, terms)
return (ch);
}
-
/* skip_comments(file) : read past comment (if any)
*/
void
-skip_comments(file)
- FILE *file;
-{
- int ch;
+skip_comments(FILE *file) {
+ int ch;
while (EOF != (ch = get_char(file))) {
/* ch is now the first character of a line.
@@ -439,16 +407,12 @@ skip_comments(file)
unget_char(ch, file);
}
-
-/* int in_file(char *string, FILE *file)
+/* int in_file(const char *string, FILE *file, int error)
* return TRUE if one of the lines in file matches string exactly,
* FALSE if no lines match, and error on error.
*/
static int
-in_file(string, file, error)
- char *string;
- FILE *file;
- int error;
+in_file(const char *string, FILE *file, int error)
{
char line[MAX_TEMPSTR];
char *endp;
@@ -470,16 +434,13 @@ in_file(string, file, error)
return (FALSE);
}
-
-/* int allowed(char *username)
+/* int allowed(const char *username)
* returns TRUE if (ALLOW_FILE exists and user is listed)
* or (DENY_FILE exists and user is NOT listed)
* or (neither file exists but user=="root" so it's okay)
*/
int
-allowed(username)
- char *username;
-{
+allowed(const char *username) {
FILE *allow = NULL;
FILE *deny = NULL;
int isallowed;
@@ -519,26 +480,20 @@ out:
return (isallowed);
}
-
void
-log_it(username, xpid, event, detail)
- const char *username;
- int xpid;
- const char *event;
- const char *detail;
-{
+log_it(const char *username, PID_T xpid, const char *event, const char *detail) {
#if defined(LOG_FILE) || DEBUGGING
- PID_T pid = xpid;
+ PID_T pid = xpid;
#endif
#if defined(LOG_FILE)
- char *msg;
- size_t msglen;
- TIME_T now = time((TIME_T) 0);
- struct tm *t = localtime(&now);
+ char *msg;
+ size_t msglen;
+ TIME_T now = time((TIME_T) 0);
+ struct tm *t = localtime(&now);
#endif /*LOG_FILE*/
#if defined(SYSLOG)
- static int syslog_open = 0;
+ static int syslog_open = 0;
#endif
#if defined(LOG_FILE)
@@ -584,7 +539,7 @@ log_it(username, xpid, event, detail)
#if defined(SYSLOG)
if (!syslog_open) {
# ifdef LOG_DAEMON
- openlog(ProgramName, LOG_PID, LOG_CRON);
+ openlog(ProgramName, LOG_PID, FACILITY);
# else
openlog(ProgramName, LOG_PID);
# endif
@@ -603,25 +558,25 @@ log_it(username, xpid, event, detail)
#endif
}
-
void
-log_close() {
+log_close(void) {
if (LogFD != ERR) {
close(LogFD);
LogFD = ERR;
}
}
-
-/* two warnings:
+/* char *first_word(char *s, char *t)
+ * return pointer to first word
+ * parameters:
+ * s - string we want the first word of
+ * t - terminators, implicitly including \0
+ * warnings:
* (1) this routine is fairly slow
* (2) it returns a pointer to static storage
*/
char *
-first_word(s, t)
- char *s; /* string we want the first word of */
- char *t; /* terminators, implicitly including \0 */
-{
+first_word(char *s, char *t) {
static char retbuf[2][MAX_TEMPSTR + 1]; /* sure wish C had GC */
static int retsel = 0;
char *rb, *rp;
@@ -646,7 +601,6 @@ first_word(s, t)
return (rb);
}
-
/* warning:
* heavily ascii-dependent.
*/
@@ -681,7 +635,6 @@ mkprint(dst, src, len)
*dst = '\0';
}
-
/* warning:
* returns a pointer to malloc'd storage, you must call free yourself.
*/
@@ -698,7 +651,6 @@ mkprints(src, len)
return (dst);
}
-
#ifdef MAIL_DATE
/* Sat, 27 Feb 1993 11:44:51 -0800 (CST)
* 1234567890123456789012345678901234567