1 |
douglas |
1 |
// Douglas Thrift |
2 |
|
|
// |
3 |
|
|
// CCS Computer Science |
4 |
|
|
// Common Functions |
5 |
|
|
// |
6 |
|
|
// $Id$ |
7 |
|
|
|
8 |
|
|
#ifndef _common_h_ |
9 |
|
|
#define _common_h_ |
10 |
|
|
|
11 |
|
|
#ifdef linux |
12 |
|
|
#undef linux |
13 |
|
|
#endif |
14 |
|
|
|
15 |
|
|
#if !defined(__FreeBSD__) && !defined(__sun__) && !defined(__APPLE__) |
16 |
|
|
#ifndef _BSD_SOURCE |
17 |
|
|
#define _BSD_SOURCE |
18 |
|
|
#endif |
19 |
|
|
#ifndef _POSIX_SOURCE |
20 |
|
|
#define _POSIX_SOURCE |
21 |
|
|
#endif |
22 |
|
|
#ifndef _GNU_SOURCE |
23 |
|
|
#define _GNU_SOURCE |
24 |
|
|
#endif |
25 |
|
|
#elif defined(__sun__) |
26 |
|
|
#define __EXTENSIONS__ |
27 |
|
|
#endif |
28 |
|
|
|
29 |
|
|
#include <pwd.h> |
30 |
|
|
#include <regex.h> |
31 |
|
|
#include <setjmp.h> |
32 |
|
|
#include <stdio.h> |
33 |
|
|
#include <stdlib.h> |
34 |
|
|
#include <string.h> |
35 |
|
|
#include <sys/param.h> |
36 |
|
|
#include <sys/stat.h> |
37 |
|
|
#include <sys/wait.h> |
38 |
|
|
#include <unistd.h> |
39 |
|
|
|
40 |
|
|
#ifndef _PASSWORD_LEN |
41 |
|
|
#define _PASSWORD_LEN BUFSIZ |
42 |
|
|
#endif |
43 |
|
|
|
44 |
|
|
#ifndef MAXLOGNAME |
45 |
|
|
#define MAXLOGNAME 17 |
46 |
|
|
#endif |
47 |
|
|
|
48 |
|
|
typedef struct |
49 |
|
|
{ |
50 |
|
|
const char *name; |
51 |
|
|
char *freebsd, *linux, *darwin, *solaris; |
52 |
|
|
} |
53 |
|
|
Shells; |
54 |
|
|
|
55 |
|
|
typedef enum { sh, csh, tcsh, bash, ksh, zsh, _3sh, custom } Shell; |
56 |
|
|
|
57 |
|
|
extern Shells shells[]; |
58 |
|
|
|
59 |
|
|
int check(int value, jmp_buf environment); |
60 |
|
|
int regcheck(int value, const regex_t *regex, jmp_buf environment); |
61 |
|
|
char *fcheck(char *value, FILE *stream, jmp_buf environment); |
62 |
|
|
void authenticate(const char *program, jmp_buf environment); |
63 |
|
|
void getpassword(char password[_PASSWORD_LEN], jmp_buf environment); |
64 |
|
|
void putpassword(char password[_PASSWORD_LEN], char *name, jmp_buf environment); |
65 |
|
|
void get(const char *prompt, regex_t *regex, char **string, jmp_buf environment); |
66 |
|
|
void setshells(Shells *shells, jmp_buf environment); |
67 |
|
|
|
68 |
|
|
#if !defined(__FreeBSD__) && !defined(__sun__) && !defined(__APPLE__) |
69 |
|
|
size_t strlcpy(char *dst, const char *src, size_t size); |
70 |
|
|
size_t strlcat(char *dst, const char *src, size_t size); |
71 |
|
|
char *fgetln(FILE * restrict stream, size_t * restrict len); |
72 |
|
|
#elif defined(__sun__) |
73 |
|
|
char *fgetln(FILE * restrict stream, size_t * restrict len); |
74 |
|
|
int setenv(const char *name, const char *value, int overwrite); |
75 |
|
|
#endif |
76 |
|
|
|
77 |
|
|
#endif//_common_h_ |