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