| 1 |
/* Away - terminal locking program |
| 2 |
* Copyright (C) 1999-2002 Cameron Moore and others |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 |
| 7 |
* of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 |
* Or try here: http://www.fsf.org/copyleft/gpl.html |
| 18 |
* |
| 19 |
* $Id: away.h,v 1.4 2002/08/12 00:33:03 hrothgar Exp $ |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef _AWAY_H |
| 23 |
#define _AWAY_H |
| 24 |
|
| 25 |
/* version and contacts */ |
| 26 |
#define VERSION "0.9.5" |
| 27 |
#define MLIST "[email protected]" |
| 28 |
|
| 29 |
/* Separator for conf file */ |
| 30 |
#define WHITESPACE " \t\n" |
| 31 |
|
| 32 |
/* macro */ |
| 33 |
#define APPEND_MAILBOX(root,path,desc) root=snocString((root),(path),(desc)) |
| 34 |
|
| 35 |
/* Max filename length */ |
| 36 |
#define FILE_NAME_LEN 1024 |
| 37 |
|
| 38 |
/* ENV variable names */ |
| 39 |
#define AWAY_RCFILE "AWAY_RCFILE" |
| 40 |
#define AWAY_NORCFILE "AWAY_NORCFILE" |
| 41 |
#define AWAY_TIME "AWAY_TIME" |
| 42 |
#define AWAY_NOTIME "AWAY_NOTIME" |
| 43 |
#define AWAY_MAIL "AWAY_MAIL" |
| 44 |
#define AWAY_PERSIST "AWAY_PERSIST" |
| 45 |
|
| 46 |
#define _GNU_SOURCE |
| 47 |
#include <stdio.h> |
| 48 |
#include <stdlib.h> |
| 49 |
#include <string.h> |
| 50 |
#include <unistd.h> |
| 51 |
#include <paths.h> |
| 52 |
#include <time.h> |
| 53 |
#include <pwd.h> |
| 54 |
#include <ctype.h> |
| 55 |
#include <signal.h> |
| 56 |
#include <getopt.h> |
| 57 |
#include <pthread.h> |
| 58 |
#include <sys/stat.h> |
| 59 |
#include <security/pam_appl.h> |
| 60 |
#include <security/pam_misc.h> |
| 61 |
|
| 62 |
/* Default conf file name */ |
| 63 |
char *rcfile = ".awayrc"; |
| 64 |
|
| 65 |
/* min mail check interval */ |
| 66 |
const int MIN_TIME = 10; |
| 67 |
|
| 68 |
/* Default settings */ |
| 69 |
int TIME = 300; |
| 70 |
short PERSIST = 1; |
| 71 |
short CHECK_MAIL = 1; |
| 72 |
|
| 73 |
/* flags to allow command line options to override conf file options */ |
| 74 |
short TIME_OP = 0; |
| 75 |
short PERSIST_OP = 0; |
| 76 |
short RCFILE_OP = 0; |
| 77 |
short MAIL_OP = 0; |
| 78 |
short NORCFILE_OP = 0; |
| 79 |
|
| 80 |
/* turned on while trying to authenticate the user */ |
| 81 |
short pam_active = 0; |
| 82 |
/* mail was found */ |
| 83 |
short mail_found = 0; |
| 84 |
/* the user has already been notified */ |
| 85 |
short notified = 0; |
| 86 |
/* name of mailbox new mail was found in */ |
| 87 |
char *found_in = NULL; |
| 88 |
|
| 89 |
/* PAM conversation struct */ |
| 90 |
static struct pam_conv conv = { misc_conv, NULL }; |
| 91 |
|
| 92 |
/* rc file commands */ |
| 93 |
typedef enum { |
| 94 |
oMail, |
| 95 |
oMaildir, |
| 96 |
oMailbox, |
| 97 |
oPersist, |
| 98 |
oTime, |
| 99 |
oBadCmd |
| 100 |
} CmdCodes; |
| 101 |
static struct { |
| 102 |
const char *name; |
| 103 |
CmdCodes opcode; |
| 104 |
} commands[] = { |
| 105 |
{ "mail", oMail }, |
| 106 |
{ "maildir", oMaildir }, |
| 107 |
{ "mailbox", oMailbox }, |
| 108 |
{ "persist", oPersist }, |
| 109 |
{ "time", oTime }, |
| 110 |
{ NULL, 0 } |
| 111 |
}; |
| 112 |
|
| 113 |
/* mailbox linked list */ |
| 114 |
typedef struct mailbox { |
| 115 |
char *path; /* path to mailbox */ |
| 116 |
char *desc; /* description of mailbox */ |
| 117 |
time_t mtime; /* last modified time (new mail) */ |
| 118 |
time_t atime; /* last accessed time (read mail) */ |
| 119 |
struct mailbox *next; |
| 120 |
} Mailbox; |
| 121 |
|
| 122 |
/* command line options for getopt */ |
| 123 |
static struct option long_options[] = |
| 124 |
{ |
| 125 |
{"help", 0, 0, 'h'}, |
| 126 |
{"mail", 0, 0, 'c'}, |
| 127 |
{"message", 0, 0, 'm'}, |
| 128 |
{"nomail", 0, 0, 'C'}, |
| 129 |
{"nopersist", 0, 0, 'P'}, |
| 130 |
{"norcfile", 0, 0, 'F'}, |
| 131 |
{"notime", 0, 0, 'T'}, |
| 132 |
{"persist", 0, 0, 'p'}, |
| 133 |
{"rcfile", 1, 0, 'f'}, |
| 134 |
{"time", 1, 0, 't'}, |
| 135 |
{"version", 0, 0, 'v'}, |
| 136 |
{0, 0, 0, 0} |
| 137 |
}; |
| 138 |
|
| 139 |
/* prototypes */ |
| 140 |
void master(void); |
| 141 |
short authenticate(char *username); |
| 142 |
char *make_path(char *dirs, char *filename); |
| 143 |
void print_version(void); |
| 144 |
void short_help(char *argv0); |
| 145 |
void ext_help(char *argv0); |
| 146 |
void stall(void); |
| 147 |
char *make_time(void); |
| 148 |
void salutations(void); |
| 149 |
short new_mail(Mailbox *mb); |
| 150 |
void mail_thread_f(Mailbox **root); |
| 151 |
static CmdCodes get_opcode(const char *cp, const char *filename, int linenum); |
| 152 |
static void *my_malloc(int n); |
| 153 |
static Mailbox *make_cell(void); |
| 154 |
static Mailbox *snocString(Mailbox *root, char *path, char *desc); |
| 155 |
static void add_mailbox(Mailbox **list, char *path, char *desc); |
| 156 |
void set_defaults(Mailbox **root, char *name); |
| 157 |
void read_config(Mailbox **root, char *homedir, char *username); |
| 158 |
void re_exec(int argc, char *argv[], int opt_cnt, short as_mesg); |
| 159 |
void check_env(void); |
| 160 |
void free_mailboxes(Mailbox *root); |
| 161 |
|
| 162 |
#endif /* _AWAY_H */ |