Debian Codegraph @

away.h

raw ◀ ▶
1 Debian patch touch this file
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 #include <termios.h>
62
63 /* Default conf file name */
64 char *rcfile = ".awayrc";
65
66 /* min mail check interval */
67 const int MIN_TIME = 10;
68
69 /* Default settings */
70 int TIME = 300;
71 short PERSIST = 1;
72 short CHECK_MAIL = 1;
73
74 /* flags to allow command line options to override conf file options */
75 short TIME_OP = 0;
76 short PERSIST_OP = 0;
77 short RCFILE_OP = 0;
78 short MAIL_OP = 0;
79 short NORCFILE_OP = 0;
80
81 /* turned on while trying to authenticate the user */
82 short pam_active = 0;
83 /* mail was found */
84 short mail_found = 0;
85 /* the user has already been notified */
86 short notified = 0;
87 /* name of mailbox new mail was found in */
88 char *found_in = NULL;
89
90 /* PAM conversation struct */
91 static struct pam_conv conv = { misc_conv, NULL };
92
93 /* rc file commands */
94 typedef enum {
95 oMail,
96 oMaildir,
97 oMailbox,
98 oPersist,
99 oTime,
100 oBadCmd
101 } CmdCodes;
102 static struct {
103 const char *name;
104 CmdCodes opcode;
105 } commands[] = {
106 { "mail", oMail },
107 { "maildir", oMaildir },
108 { "mailbox", oMailbox },
109 { "persist", oPersist },
110 { "time", oTime },
111 { NULL, 0 }
112 };
113
114 /* mailbox linked list */
115 typedef struct mailbox {
116 char *path; /* path to mailbox */
117 char *desc; /* description of mailbox */
118 time_t mtime; /* last modified time (new mail) */
119 time_t atime; /* last accessed time (read mail) */
120 struct mailbox *next;
121 } Mailbox;
122
123 /* command line options for getopt */
124 static struct option long_options[] =
125 {
126 {"help", 0, 0, 'h'},
127 {"mail", 0, 0, 'c'},
128 {"message", 0, 0, 'm'},
129 {"nomail", 0, 0, 'C'},
130 {"nopersist", 0, 0, 'P'},
131 {"norcfile", 0, 0, 'F'},
132 {"notime", 0, 0, 'T'},
133 {"persist", 0, 0, 'p'},
134 {"rcfile", 1, 0, 'f'},
135 {"time", 1, 0, 't'},
136 {"version", 0, 0, 'v'},
137 {0, 0, 0, 0}
138 };
139
140 /* prototypes */
141 void master(void);
142 short authenticate(char *username);
143 char *make_path(char *dirs, char *filename);
144 void print_version(void);
145 void short_help(char *argv0);
146 void ext_help(char *argv0);
147 void stall(void);
148 char *make_time(void);
149 void salutations(void);
150 short new_mail(Mailbox *mb);
151 void mail_thread_f(Mailbox **root);
152 static CmdCodes get_opcode(const char *cp, const char *filename, int linenum);
153 static void *my_malloc(int n);
154 static Mailbox *make_cell(void);
155 static Mailbox *snocString(Mailbox *root, char *path, char *desc);
156 static void add_mailbox(Mailbox **list, char *path, char *desc);
157 void set_defaults(Mailbox **root, char *name);
158 void read_config(Mailbox **root, char *homedir, char *username);
159 void re_exec(int argc, char *argv[], int opt_cnt, short as_mesg);
160 void check_env(void);
161 void free_mailboxes(Mailbox *root);
162
163 #endif /* _AWAY_H */