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