#include <sys/types.h>
#include <sys/param.h>
#include "compat.h"
#include <bitstring.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <sys/wait.h>
#include "pathnames.h"
#include "config.h"
#include "externs.h"
#define TRUE 1
#define FALSE 0
#define OK 0
#define ERR (-1)
#ifndef DEBUGGING
#define DEBUGGING FALSE
#endif
#define READ_PIPE 0
#define WRITE_PIPE 1
#define STDIN 0
#define STDOUT 1
#define STDERR 2
#define ERROR_EXIT 1
#define OK_EXIT 0
#define MAX_FNAME 100
#define MAX_COMMAND 1000
#define MAX_ENVSTR 1000
#define MAX_TEMPSTR 100
#define MAX_UNAME 20
#define ROOT_UID 0
#define ROOT_USER "root"
#define DEXT 0x0001
#define DSCH 0x0002
#define DPROC 0x0004
#define DPARS 0x0008
#define DLOAD 0x0010
#define DMISC 0x0020
#define DTEST 0x0040
#define DBIT 0x0080
#define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
#define REG register
#define PPC_NULL ((char **)NULL)
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif
#define Skip_Blanks(c, f) \
while (c == '\t' || c == ' ') \
c = get_char(f);
#define Skip_Nonblanks(c, f) \
while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
c = get_char(f);
#define Skip_Line(c, f) \
do {c = get_char(f);} while (c != '\n' && c != EOF);
#if DEBUGGING
# define Debug(mask, message) \
if ( (DebugFlags & (mask) ) == (mask) ) \
printf message;
#else
# define Debug(mask, message) \
;
#endif
#define MkLower(ch) (isupper(ch) ? tolower(ch) : ch)
#define MkUpper(ch) (islower(ch) ? toupper(ch) : ch)
#define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
LineNumber = ln; \
}
#define FIRST_MINUTE 0
#define LAST_MINUTE 59
#define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
#define FIRST_HOUR 0
#define LAST_HOUR 23
#define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
#define FIRST_DOM 1
#define LAST_DOM 31
#define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
#define FIRST_MONTH 1
#define LAST_MONTH 12
#define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
#define FIRST_DOW 0
#define LAST_DOW 7
#define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
#ifdef LOGIN_CAP
#define RESOURCE_RC "daemon"
#endif
typedef struct _entry {
struct _entry *next;
uid_t uid;
gid_t gid;
#ifdef LOGIN_CAP
char *class;
#endif
char **envp;
char *cmd;
bitstr_t bit_decl(minute, MINUTE_COUNT);
bitstr_t bit_decl(hour, HOUR_COUNT);
bitstr_t bit_decl(dom, DOM_COUNT);
bitstr_t bit_decl(month, MONTH_COUNT);
bitstr_t bit_decl(dow, DOW_COUNT);
int flags;
#define DOM_STAR 0x01
#define DOW_STAR 0x02
#define WHEN_REBOOT 0x04
} entry;
typedef struct _user {
struct _user *next, *prev;
char *name;
time_t mtime;
entry *crontab;
} user;
typedef struct _cron_db {
user *head, *tail;
time_t mtime;
} cron_db;
void set_cron_uid __P((void)),
set_cron_cwd __P((void)),
load_database __P((cron_db *)),
open_logfile __P((void)),
sigpipe_func __P((void)),
job_add __P((entry *, user *)),
do_command __P((entry *, user *)),
link_user __P((cron_db *, user *)),
unlink_user __P((cron_db *, user *)),
free_user __P((user *)),
env_free __P((char **)),
unget_char __P((int, FILE *)),
free_entry __P((entry *)),
acquire_daemonlock __P((int)),
skip_comments __P((FILE *)),
log_it __P((char *, int, char *, char *)),
log_close __P((void));
int job_runqueue __P((void)),
set_debug_flags __P((char *)),
get_char __P((FILE *)),
get_string __P((char *, int, FILE *, char *)),
swap_uids __P((void)),
load_env __P((char *, FILE *)),
cron_pclose __P((FILE *)),
strcmp_until __P((char *, char *, int)),
allowed __P((char *)),
strdtb __P((char *));
char *env_get __P((char *, char **)),
*arpadate __P((time_t *)),
*mkprints __P((unsigned char *, unsigned int)),
*first_word __P((char *, char *)),
**env_init __P((void)),
**env_copy __P((char **)),
**env_set __P((char **, char *));
user *load_user __P((int, struct passwd *, char *)),
*find_user __P((cron_db *, char *));
entry *load_entry __P((FILE *, void (*)(),
struct passwd *, char **));
FILE *cron_popen __P((char *, char *));
#ifdef MAIN_PROGRAM
# if !defined(LINT) && !defined(lint)
char *copyright[] = {
"@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie",
"@(#) All rights reserved"
};
# endif
char *MonthNames[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
NULL
};
char *DowNames[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
NULL
};
char *ProgramName;
int LineNumber;
time_t TargetTime;
# if DEBUGGING
int DebugFlags;
char *DebugFlagNames[] = {
"ext", "sch", "proc", "pars", "load", "misc", "test", "bit",
NULL
};
# endif
#else
extern char *copyright[],
*MonthNames[],
*DowNames[],
*ProgramName;
extern int LineNumber;
extern time_t TargetTime;
# if DEBUGGING
extern int DebugFlags;
extern char *DebugFlagNames[];
# endif
#endif