1 # include <stdio.h> 2 # include <pwd.h> 3 # include "dlvrmail.h" 4 # include <whoami.h> 5 6 /* 7 ** CONF.C -- Delivermail Configuration Tables. 8 ** 9 ** Defines the configuration of this installation. 10 ** 11 ** The first table describes available mailers. This is 12 ** just a list of argument vectors, with the following 13 ** codes embedded: 14 ** $u -- insert the user name. 15 ** $h -- insert the host name. 16 ** $f -- insert the from person name. 17 ** $c -- insert the hop count. 18 ** This stuff is interpreted in buildmail. There are two 19 ** important conventions here: entry zero must be the 20 ** local mailer & entry one must be the shell. 21 ** 22 ** The second table gives a list of special characters. This 23 ** table is scanned linearly by parse() until an entry is 24 ** found using one of the magic characters. Other fields 25 ** give more information on how to handle it. 26 ** 27 ** Defined Constants: 28 ** M_* -- indices into Mailer, used only in this module. 29 ** 30 ** Defines: 31 ** Mailer -- the mailer descriptor table. 32 ** ParseTab -- the parse table. 33 ** 34 ** Notes: 35 ** Ingres 11/70 version. 36 ** 37 ** History: 38 ** 3/5/80 -- Generalized to use <whoami.h>. 39 ** 12/26/79 -- written for Ingres 11/70. 40 */ 41 42 43 44 45 46 # ifdef ING70 47 static char *BerkLocal[] = { "i", "ingres", "ing70", NULL }; 48 char *MyLocNam = "Ing70"; 49 # define HASARPA 50 # define V6 51 # endif ING70 52 53 # ifdef INGVAX 54 /* untested */ 55 static char *BerkLocal[] = { "j", "ingvax", NULL }; 56 char *MyLocNam = "IngVax"; 57 # endif INGVAX 58 59 # ifdef CSVAX 60 /* untested */ 61 static char *BerkLocal[] = { "v", "csvax", "vax", NULL }; 62 char *MyLocNam = "CSVax"; 63 # define HASUUCP 64 # define NETV6MAIL 65 # endif CSVAX 66 67 # ifdef CORY 68 /* untested */ 69 static char *BerkLocal[] = { "y", "cory", NULL }; 70 char *MyLocNam = "Cory"; 71 # endif CORY 72 73 # ifdef IMAGE 74 /* untested */ 75 static char *BerkLocal[] = { "m", "image", NULL }; 76 char *MyLocNam = "Image"; 77 # define V6 78 # endif IMAGE 79 80 # ifdef ESVAX 81 /* untested */ 82 static char *BerkLocal[] = { "o", "esvax", NULL }; 83 char *MyLocNam = "ESVax"; 84 # endif ESVAX 85 86 # ifdef EECS40 87 /* untested */ 88 static char *BerkLocal[] = { "z", "eecs40", NULL }; 89 char *MyLocNam = "EECS40"; 90 # define V6 91 # endif EECS40 92 93 struct mailer Mailer[] = 94 { 95 /* local mail -- must be #0 */ 96 { 97 # ifdef NETV6MAIL 98 "/usr/net/bin/v6mail", 99 # else 100 "/bin/mail", 101 # endif 102 M_ROPT|M_NOHOST|M_STRIPQ, EX_NOUSER, NULL, 103 { "...local%mail", "-d", "$u", NULL } 104 }, 105 /* pipes through programs -- must be #1 */ 106 { 107 "/bin/csh", 108 M_HDR|M_NOHOST, EX_UNAVAIL, NULL, 109 { "...prog%mail", "-fc", "$u", NULL } 110 }, 111 /* local berkeley mail */ 112 { 113 "/usr/net/bin/sendberkmail", 114 M_FOPT|M_HDR, EX_UNAVAIL, BerkLocal, 115 { "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL } 116 }, 117 /* arpanet mail */ 118 { 119 "/usr/lib/mailers/arpa", 120 0, 0, NULL, 121 { "...arpa%mail", "$f", "$h", "$u", NULL } 122 }, 123 /* uucp mail (cheat & use Bell's v7 mail) */ 124 { 125 # ifdef UCKMAIL 126 "/bin/badmail", 127 # else 128 "/bin/mail", 129 # endif 130 M_ROPT|M_NOHOST|M_STRIPQ, EX_NOUSER, NULL, 131 # ifdef DUMBMAIL 132 { "...uucp%mail", "$h!$u", NULL } 133 # else 134 { "...uucp%mail", "-d", "$h!$u", NULL } 135 # endif DUMBMAIL 136 }, 137 }; 138 139 # define M_LOCAL 0 140 # define M_BERK 2 141 # define M_ARPA 3 142 # define M_UUCP 4 143 144 145 146 struct parsetab ParseTab[] = 147 { 148 ':', M_BERK, P_ONE, NULL, 149 # ifdef HASARPA 150 '@', M_ARPA, P_HLAST|P_USR_UPPER, NULL, 151 # else 152 '@', M_BERK, P_HLAST|P_USR_UPPER|P_MOVE, "ing70", 153 # endif HASARPA 154 '^', -1, P_MAP, "!", 155 # ifdef HASUUCP 156 '!', M_UUCP, 0, NULL, 157 # else 158 '!', M_BERK, P_MOVE, "csvax", 159 # endif HASUUCP 160 '.', -1, P_MAP|P_ONE, ":", 161 '\0', M_LOCAL, P_MOVE, "", 162 }; 163 /* 164 ** GETNAME -- Get the current users login name. 165 ** 166 ** This is in config.c because it is somewhat machine dependent. 167 ** Examine it carefully for your installation. 168 ** 169 ** Algorithm: 170 ** See if the person is logged in. If so, return 171 ** the name s/he is logged in as. 172 ** Look up the user id in /etc/passwd. If found, 173 ** return that name. 174 ** Return NULL. 175 ** 176 ** Parameters: 177 ** none 178 ** 179 ** Returns: 180 ** The login name of this user. 181 ** NULL if this person is noone. 182 ** 183 ** Side Effects: 184 ** none 185 ** 186 ** Requires: 187 ** getlogin (sys) 188 ** getpwuid (sys) 189 ** getuid (sys) 190 ** 191 ** Called By: 192 ** main 193 ** 194 ** History: 195 ** 12/26/79 -- written. 196 */ 197 198 char * 199 getname() 200 { 201 register char *p; 202 register struct passwd *w; 203 extern char *getlogin(); 204 extern struct passwd *getpwuid(); 205 static char namebuf[9]; 206 207 p = getlogin(); 208 if (p != NULL && p[0] != '\0') 209 return (p); 210 # ifdef V6 211 w = getpwuid(getuid() & 0377); 212 # else 213 w = getpwuid(getuid()); 214 # endif V6 215 if (w != NULL) 216 { 217 strcpy(namebuf, w->pw_name); 218 return (namebuf); 219 } 220 return (NULL); 221 } 222 223 # ifdef V6 224 /* 225 ** TTYPATH -- Get the path of the user's tty -- Version 6 version. 226 ** 227 ** Returns the pathname of the user's tty. Returns NULL if 228 ** the user is not logged in or if s/he has write permission 229 ** denied. 230 ** 231 ** Parameters: 232 ** none 233 ** 234 ** Returns: 235 ** pathname of the user's tty. 236 ** NULL if not logged in or write permission denied. 237 ** 238 ** Side Effects: 239 ** none. 240 ** 241 ** WARNING: 242 ** Return value is in a local buffer. 243 ** 244 ** Requires: 245 ** stat (sys) 246 ** ttyn (sys) 247 ** open (sys) 248 ** read (sys) 249 ** close (sys) 250 ** seek (sys) 251 ** 252 ** Called By: 253 ** savemail 254 ** 255 ** History: 256 ** 1/12/80 -- written. 257 */ 258 259 # include <sys/types.h> 260 # include <sys/stat.h> 261 262 char * 263 ttypath() 264 { 265 struct stat stbuf; 266 register int i; 267 static char pathn[] = "/dev/ttyx"; 268 extern int errno; 269 270 /* compute the pathname of the controlling tty */ 271 if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x') 272 { 273 errno = 0; 274 return (NULL); 275 } 276 pathn[8] = i; 277 278 /* see if we have write permission */ 279 if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 280 { 281 errno = 0; 282 return (NULL); 283 } 284 285 /* see if the user is logged in */ 286 if (getlogin() == NULL) 287 return (NULL); 288 289 /* looks good */ 290 return (pathn); 291 } 292 /* 293 ** FDOPEN -- Open a stdio file given an open file descriptor. 294 ** 295 ** This is included here because it is standard in v7, but we 296 ** need it in v6. 297 ** 298 ** Algorithm: 299 ** Open /dev/null to create a descriptor. 300 ** Close that descriptor. 301 ** Copy the existing fd into the descriptor. 302 ** 303 ** Parameters: 304 ** fd -- the open file descriptor. 305 ** type -- "r", "w", or whatever. 306 ** 307 ** Returns: 308 ** The file descriptor it creates. 309 ** 310 ** Side Effects: 311 ** none 312 ** 313 ** Requires: 314 ** fopen (sys) 315 ** 316 ** Called By: 317 ** deliver 318 ** 319 ** Notes: 320 ** The mode of fd must match "type". 321 */ 322 323 FILE * 324 fdopen(fd, type) 325 int fd; 326 char *type; 327 { 328 register FILE *f; 329 330 f = fopen("/dev/null", type); 331 close(fileno(f)); 332 fileno(f) = fd; 333 return (f); 334 } 335 /* 336 ** INDEX -- Return pointer to character in string 337 ** 338 ** For V7 compatibility. 339 ** 340 ** Parameters: 341 ** s -- a string to scan. 342 ** c -- a character to look for. 343 ** 344 ** Returns: 345 ** If c is in s, returns the address of the first 346 ** instance of c in s. 347 ** NULL if c is not in s. 348 ** 349 ** Side Effects: 350 ** none. 351 ** 352 ** Requires: 353 ** none. 354 ** 355 ** History: 356 ** 3/14/80 -- written. Why isn't this in -lS? 357 */ 358 359 index(s, c) 360 register char *s; 361 register char c; 362 { 363 while (*s != '\0') 364 { 365 if (*s++ == c) 366 return (--s); 367 } 368 return (NULL); 369 } 370 # endif V6 371 372 # ifndef V6 373 /* 374 ** TTYPATH -- Get the path of the user's tty -- Version 7 version. 375 ** 376 ** Returns the pathname of the user's tty. Returns NULL if 377 ** the user is not logged in or if s/he has write permission 378 ** denied. 379 ** 380 ** Parameters: 381 ** none 382 ** 383 ** Returns: 384 ** pathname of the user's tty. 385 ** NULL if not logged in or write permission denied. 386 ** 387 ** Side Effects: 388 ** none. 389 ** 390 ** WARNING: 391 ** Return value is in a local buffer. 392 ** 393 ** Requires: 394 ** stat (sys) 395 ** ttyn (sys) 396 ** open (sys) 397 ** read (sys) 398 ** close (sys) 399 ** seek (sys) 400 ** 401 ** Called By: 402 ** savemail 403 ** 404 ** History: 405 ** 1/12/80 -- written. 406 */ 407 408 # include <sys/types.h> 409 # include <sys/stat.h> 410 411 char * 412 ttypath() 413 { 414 struct stat stbuf; 415 register char *pathn; 416 extern int errno; 417 extern char *ttyname(); 418 419 /* compute the pathname of the controlling tty */ 420 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL) 421 { 422 errno = 0; 423 return (NULL); 424 } 425 426 /* see if we have write permission */ 427 if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode)) 428 { 429 errno = 0; 430 return (NULL); 431 } 432 433 /* see if the user is logged in */ 434 if (getlogin() == NULL) 435 return (NULL); 436 437 /* looks good */ 438 return (pathn); 439 } 440 # endif V6 441