1 /* 2 ** This is the header file for qpage. It should not necessary to 3 ** change anything in this file. Edit config.input as appropriate 4 ** and then type "./configure" to create a customized config.h for 5 ** your system. Then just type "make" to build qpage. 6 */ 7 #include "config.h" 8 9 10 #define PROGRAM_NAME "qpage" 11 12 13 #ifndef TRUE 14 #define TRUE 1 15 #endif 16 #ifndef FALSE 17 #define FALSE 0 18 #endif 19 20 21 /* 22 ** tell lint to shut up 23 */ 24 #ifdef lint 25 #define printf (void)printf 26 #define fprintf (void)fprintf 27 #endif 28 29 #define VERSION "3.3" 30 #define COMMENTS_ANYWHERE 31 32 #ifndef QPAGE_CONFIG 33 #define QPAGE_CONFIG "/etc/qpage.cf" 34 #endif 35 36 #ifndef DEFAULT_LOCKDIR 37 #define DEFAULT_LOCKDIR "/var/spool/locks" 38 #endif 39 40 #ifndef SYSLOG_FACILITY 41 #define SYSLOG_FACILITY LOG_DAEMON 42 #endif 43 44 #ifndef HAVE_STRERROR 45 extern char *sys_errlist[]; 46 #define strerror(x) sys_errlist[x] 47 #endif 48 49 #ifndef SNPP_SERVER 50 #define SNPP_SERVER "localhost" 51 #endif 52 53 #ifndef DAEMON_USER 54 #define DAEMON_USER "nobody" 55 #endif 56 57 #define SNPP_SVC_NAME "snpp" 58 #define SNPP_SVC_PORT 444 59 60 #define MAXMSGSIZE 250 /* imposed by TAP blocksize */ 61 62 #define MAXBADCOMMANDS 10 63 #define BUFCHUNKSIZE 1024 64 65 #define DEFAULT_LEVEL 1 66 #define DEFAULT_IDENTTIMEOUT 10 67 #define DEFAULT_SNPPTIMEOUT 60 68 #define DEFAULT_QUEUEDIR "/var/spool/qpage" 69 70 /* 71 ** default values for paging services 72 */ 73 #define DEFAULT_INITCMD "ATZ" 74 #define DEFAULT_DIALCMD "ATDT" 75 #define DEFAULT_BAUDRATE B300 76 #define DEFAULT_PARITY EVEN /* see parity_t below */ 77 #define DEFAULT_MAXMSGSIZE 80 78 #define DEFAULT_MAXPAGES 9 79 #define DEFAULT_MAXTRIES 6 80 #define DEFAULT_IDENTFROM TRUE 81 #define DEFAULT_ALLOWPID FALSE 82 #define DEFAULT_STRIP TRUE 83 #define DEFAULT_PREFIX TRUE 84 85 /* 86 ** service level at which e-mail notifications shold be sent 87 */ 88 #define LEVEL_SENDMAIL 0 89 90 #define F_SENT (1<<0) /* msg sent successfully */ 91 #define F_FAILED (1<<1) /* msg failed */ 92 #define F_BUSY (1<<2) /* modem got BUSY */ 93 #define F_NOCARRIER (1<<3) /* modem got NO CARRIER */ 94 #define F_NOMODEM (1<<4) /* modem was unavailable */ 95 #define F_FORCED (1<<5) /* remote sent <RS> */ 96 #define F_NOPROMPT (1<<6) /* didn't find ID= prompt */ 97 #define F_UNKNOWN (1<<7) /* unknown error */ 98 #define F_REJECT (1<<8) /* page rejected by service */ 99 #define F_RAWPID (1<<9) /* user specified a PID */ 100 #define F_SENDMAIL (1<<10) /* send mail to sender */ 101 #define F_SENTMAIL (1<<11) /* sent mail to sender */ 102 #define F_SENTADMIN (1<<12) /* sent mail to administrator */ 103 #define F_BADPAGE (1<<13) /* the entire page is bad */ 104 105 #define CALLSTATUSFLAGS 0x01ff /* per-call status flags */ 106 107 #define CHAR_STX '\002' 108 #define CHAR_ETX '\003' 109 #define CHAR_ETB '\027' 110 #define CHAR_US '\037' 111 112 #define INVALID_TIME ((time_t)-1) 113 114 115 /* 116 ** select.h is broken for Solaris 2.x. It defines FD_ZERO 117 ** as a macro which calls memset(). Unfortunately memset() 118 ** returns a value, which means FD_ZERO returns a value, 119 ** contrary to the description in the "select" man page. 120 ** 121 ** We cannot blindly cast this to (void) at compile time 122 ** because it breaks on some platforms (e.g. Linux). 123 */ 124 #if defined(lint) && defined(SOLARIS2) 125 #define FD_ZERO_LINTED(x) (void)FD_ZERO(x) 126 #else 127 #define FD_ZERO_LINTED(x) FD_ZERO(x) 128 #endif 129 130 131 enum parity { 132 NONE = 0, 133 ODD = 1, 134 EVEN = 2 135 }; 136 typedef enum parity parity_t; 137 138 139 struct modem { 140 struct modem *next; /* next node in the list */ 141 char *name; /* name of this modem */ 142 char *text; /* optional text description */ 143 char *device; /* path to modem device */ 144 char *initcmd; /* initialization command */ 145 char *dialcmd; /* dial command */ 146 }; 147 typedef struct modem modem_t; 148 149 150 struct service { 151 struct service *next; /* next node in the list */ 152 char *name; /* name of the service */ 153 char *text; /* optional text description */ 154 char *device; /* path to modem device */ 155 char *dialcmd; /* dial command */ 156 char *phone; /* IXO/TAP phone number */ 157 char *password; /* service password */ 158 int baudrate; /* modem speed */ 159 parity_t parity; /* modem parity */ 160 int maxmsgsize; /* max length of a page */ 161 int maxpages; /* max segments per page */ 162 int maxtries; /* max tries per page */ 163 int identfrom; /* who page is from */ 164 int allowpid; /* page must be in qpage.cf? */ 165 int msgprefix; /* prefix msgs with <from> */ 166 int flags; /* not used at this time */ 167 }; 168 typedef struct service service_t; 169 170 171 struct pager { 172 struct pager *next; /* next node in the list */ 173 char *name; /* name of this entry */ 174 char *text; /* optional text description */ 175 char *pagerid; /* IXO pagerid */ 176 service_t *service; /* associated paging service */ 177 int flags; /* status flags */ 178 }; 179 typedef struct pager pager_t; 180 181 182 struct member { 183 struct member *next; /* next node in the list */ 184 pager_t *pager; /* list member */ 185 char *schedule; /* when this member is valid */ 186 int flags; /* status flags */ 187 }; 188 typedef struct member member_t; 189 190 191 struct pgroup { 192 struct pgroup *next; /* next node in the list */ 193 char *name; /* name of this group */ 194 char *text; /* optional text description */ 195 member_t *members; /* list of group members */ 196 int flags; /* status flags */ 197 }; 198 typedef struct pgroup pgroup_t; 199 200 201 struct rcpt { 202 struct rcpt *next; /* next node in the list */ 203 char *pager; /* name of this recipient */ 204 char *coverage; /* name of paging service */ 205 time_t holduntil; /* hold page until this time */ 206 time_t lasttry; /* time of last page attempt */ 207 int goodtries; /* number of dial attempts */ 208 int tries; /* total number of attempts */ 209 int level; /* level of service */ 210 int flags; /* status flags */ 211 }; 212 typedef struct rcpt rcpt_t; 213 214 215 typedef struct page { 216 struct page *next; /* next node in the list */ 217 FILE *peer; /* connected TCP socket */ 218 char *filename; /* name of queue file */ 219 rcpt_t *rcpts; /* recipient list */ 220 time_t created; /* time page was submitted */ 221 char *message; /* page contents */ 222 char *messageid; /* unique ID */ 223 char *auth; /* authenticated submitter */ 224 char *ident; /* RFC-1413 results */ 225 char *from; /* CALLerid argument */ 226 char *hostname; /* page origin */ 227 char *status; /* IXO status */ 228 int flags; /* status flags */ 229 } PAGE; 230 231 232 struct job { 233 struct job *next; /* next node in the list */ 234 PAGE *p; /* page structure */ 235 rcpt_t *rcpt; /* single recipient */ 236 service_t *service; /* associated service */ 237 pager_t *pager; /* name of recipient */ 238 }; 239 typedef struct job job_t; 240 241 242 /* 243 ** global variables 244 */ 245 extern int Debug; 246 extern int Silent; 247 extern int Interactive; 248 extern int IdentTimeout; 249 extern int SNPPTimeout; 250 extern volatile int JobsPending; 251 extern volatile int ReReadConfig; 252 extern int Synchronous; 253 extern char *PIDfile; 254 extern char *ConfigFile; 255 extern char *Administrator; 256 extern char *ForceHostname; 257 extern char *SigFile; 258 extern char *QueueDir; 259 extern char *LockDir; 260 extern service_t *Services; 261 extern pager_t *Pagers; 262 extern pgroup_t *Groups; 263 extern modem_t *Modems; 264 265 #ifndef CLIENT_ONLY 266 extern jmp_buf TimeoutEnv; 267 #endif 268 269 /* 270 ** misc functions 271 */ 272 extern void *lookup(void *list, char *name); 273 extern void *my_realloc(void *ptr, int len); 274 extern void my_free(void *ptr); 275 extern void clear_page(PAGE *p, int save); 276 extern void send_pages(job_t *jobs); 277 extern void read_mail(PAGE *p); 278 extern void qpage_log(int pri, char *fmt, ...); 279 extern time_t snpptime(char *arg); 280 extern time_t parse_time(char *str); 281 extern int become_daemon(int sleeptime, short port); 282 extern int submit_page(PAGE *p, char *server); 283 extern int lock_file(int fd, int mode, int block); 284 extern int lock_queue(void); 285 extern int write_page(PAGE *p, int new); 286 extern int runqueue(void); 287 extern int insert_jobs(job_t **joblist, PAGE *p); 288 extern int lock_modem(char *device); 289 extern void unlock_modem(char *device); 290 extern char *ident(int peer); 291 extern char *getinput(FILE *fp, int oneline); 292 extern char *get_user(void); 293 extern char *safe_string(char *str); 294 extern char *safe_strtok(char *str, char *sep, char **l, char *r); 295 extern char *strjoin(char *str1, char *str2); 296 extern int get_qpage_config(char *filename); 297 extern int on_duty(char *schedule, time_t when); 298 extern int showqueue(void); 299 extern char *my_ctime(time_t *clock); 300 extern char *msgcpy(char *dst, char *src, int len); 301 extern void strip(char **str); 302 extern void get_sysinfo(void); 303 extern void notify_submitter(PAGE *p); 304 extern void notify_administrator(PAGE *p); 305 extern void newmsgid(char *buff); 306 extern void drop_root_privileges(void); 307 extern void dump_qpage_config(char *filename); 308 309 /* 310 ** signal handlers 311 */ 312 extern void sigalrm(void); 313 extern void sigchld(void); 314 extern void sighup(void); 315 extern void sigterm(void); 316 extern void sigusr1(void); 317