1 |
|
|
2 |
/* Copyright (C) 1999 Beau Kuiper |
/* Copyright (C) 1999 Beau Kuiper |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
33 |
#define TRUE !FALSE |
#define TRUE !FALSE |
34 |
|
|
35 |
/* constants declaring various log levels. */ |
/* constants declaring various log levels. */ |
36 |
#define MYLOG_DACCESS 1 /* denied access to server because of ip */ |
#define MYLOG_DACCESS 1 /* denied access to server because of ip */ |
37 |
#define MYLOG_FTRANS 2 /* file transfer */ |
#define MYLOG_FTRANS 2 /* file transfer */ |
38 |
#define MYLOG_COMMAND 4 /* command from client */ |
#define MYLOG_COMMAND 4 /* command from client */ |
39 |
#define MYLOG_RESPONSE 8 /* respone to client commands */ |
#define MYLOG_RESPONSE 8 /* respone to client commands */ |
40 |
#define MYLOG_INFO 16 /* informational logs */ |
#define MYLOG_INFO 16 /* informational logs */ |
41 |
#define MYLOG_LOGIN 32 /* login information */ |
#define MYLOG_LOGIN 32 /* login information */ |
42 |
#define MYLOG_DEBUG 64 /* debug log */ |
#define MYLOG_DEBUG 64 /* debug log */ |
43 |
|
|
44 |
/* set err to this to tell the server the result of getting an auth handle */ |
/* set err to this to tell the server the result of getting an auth handle */ |
45 |
#define AUTH_OK 0 /* got handle, everything good */ |
#define AUTH_OK 0 /* got handle, everything good */ |
46 |
#define AUTH_USERNKNOW 1 /* This module is not responsible for |
#define AUTH_USERNKNOW 1 /* This module is not responsible for |
47 |
current user, move to next module */ |
* current user, move to next module */ |
48 |
#define AUTH_ERROR 2 /* A bad error occured, stop attempting |
#define AUTH_ERROR 2 /* A bad error occured, stop attempting |
49 |
to authenticate user */ |
* to authenticate user */ |
50 |
|
|
51 |
/* a couple of macros to help :-) */ |
/* a couple of macros to help :-) */ |
52 |
#define MAXIMUM(x, y) (x) > (y) ? (x) : (y) |
#define MAXIMUM(x, y) (x) > (y) ? (x) : (y) |
61 |
int fd; |
int fd; |
62 |
void *buffer; |
void *buffer; |
63 |
int eof; |
int eof; |
64 |
} NEWFILE; |
} |
65 |
|
NEWFILE; |
66 |
|
|
67 |
/* here as some prototypes for functions you can use */ |
/* here as some prototypes for functions you can use */ |
68 |
|
|
73 |
|
|
74 |
/* Almost same a realloc, execpt supply double pointer of memory area(inarea) |
/* Almost same a realloc, execpt supply double pointer of memory area(inarea) |
75 |
* and the new size */ |
* and the new size */ |
76 |
void reallocwrapper(int size, void **inarea); |
void reallocwrapper(int size, |
77 |
|
void **inarea); |
78 |
|
|
79 |
/* Same as strdup, but checks for out of memory result */ |
/* Same as strdup, but checks for out of memory result */ |
80 |
char *strdupwrapper(char *s); |
char *strdupwrapper(char *s); |
87 |
/* just memmove because muddleftpd will supply a replacement if the system |
/* just memmove because muddleftpd will supply a replacement if the system |
88 |
* doesn't supply one */ |
* doesn't supply one */ |
89 |
#ifndef HAVE_MEMMOVE |
#ifndef HAVE_MEMMOVE |
90 |
char *memmove(void *dest, void *src, int n); |
char *memmove(void *dest, |
91 |
|
void *src, |
92 |
|
int n); |
93 |
#endif |
#endif |
94 |
|
|
95 |
/* STRING FUNCTIONS */ |
/* STRING FUNCTIONS */ |
99 |
void strtrimspace(char *string); |
void strtrimspace(char *string); |
100 |
|
|
101 |
/* This counts to number of occurences of char tok in the supplied string */ |
/* This counts to number of occurences of char tok in the supplied string */ |
102 |
int strchrcount(char *string, char tok); |
int strchrcount(char *string, |
103 |
|
char tok); |
104 |
|
|
105 |
/* this is vsprintf except the result is given as a string allocated using |
/* this is vsprintf except the result is given as a string allocated using |
106 |
* mallocwrapper. Use freewrapper to reclaim the space it uses */ |
* mallocwrapper. Use freewrapper to reclaim the space it uses */ |
107 |
char *safe_vsnprintf(char *format, va_list ap); |
char *safe_vsnprintf(char *format, |
108 |
|
va_list ap); |
109 |
|
|
110 |
/* this is the same as sprintf execpt the result is given as a string allocated |
/* this is the same as sprintf execpt the result is given as a string allocated |
111 |
* in dynamic memory using mallocwrapper. Use freewrapper to free it */ |
* in dynamic memory using mallocwrapper. Use freewrapper to free it */ |
112 |
char *safe_snprintf(char *format, ...); |
char *safe_snprintf(char *format, |
113 |
|
...); |
114 |
|
|
115 |
/* gets suplementary gids of user */ |
/* gets suplementary gids of user */ |
116 |
gid_t *getusergrouplist(char *username); |
gid_t *getusergrouplist(char *username); |
118 |
/* these are for really bad errors. Don't use either errormsg or errormsgfatal. |
/* these are for really bad errors. Don't use either errormsg or errormsgfatal. |
119 |
* Use the ERRORMSG and ERRORMSGFATAL macros instead. BTW, ONLY USE THESE |
* Use the ERRORMSG and ERRORMSGFATAL macros instead. BTW, ONLY USE THESE |
120 |
* FOR ERRORS THAT CANNOT BE SOLVED ANYWAY ELSE */ |
* FOR ERRORS THAT CANNOT BE SOLVED ANYWAY ELSE */ |
121 |
void errormsg( char *errmessage, char *file, int line ); |
void errormsg(char *errmessage, |
122 |
void errormsgfatal( char *errmessage, char *file, int line ); |
char *file, |
123 |
|
int line); |
124 |
|
void errormsgfatal(char *errmessage, |
125 |
|
char *file, |
126 |
|
int line); |
127 |
|
|
128 |
#define ERRORMSGFATAL(x) errormsgfatal(x, __FILE__, __LINE__) |
#define ERRORMSGFATAL(x) errormsgfatal(x, __FILE__, __LINE__) |
129 |
#define ERRORMSG(x) errormsg(x, __FILE__, __LINE__) |
#define ERRORMSG(x) errormsg(x, __FILE__, __LINE__) |
130 |
|
|
133 |
/* Adds a log entry to muddleftpd's logs. type is one of the constants |
/* Adds a log entry to muddleftpd's logs. type is one of the constants |
134 |
* specified above. peer is the same peer pointer passed to the gethandle |
* specified above. peer is the same peer pointer passed to the gethandle |
135 |
* function. desc is the string to add to the log */ |
* function. desc is the string to add to the log */ |
136 |
extern void log_addentry(int type, void *peer, char *desc); |
extern void log_addentry(int type, |
137 |
|
void *peer, |
138 |
|
char *desc); |
139 |
|
|
140 |
/* Exactly the same a log_addentry, but muddleftpd will use freewrapper |
/* Exactly the same a log_addentry, but muddleftpd will use freewrapper |
141 |
* on desc so you can use safe_snprintf for desc */ |
* on desc so you can use safe_snprintf for desc */ |
142 |
extern void log_giveentry(int type, void *peer, char *desc); |
extern void log_giveentry(int type, |
143 |
|
void *peer, |
144 |
|
char *desc); |
145 |
|
|
146 |
/* the debug log */ |
/* the debug log */ |
147 |
extern void debuglog(char *format, ...); |
extern void debuglog(char *format, |
148 |
|
...); |
149 |
|
|
150 |
/* CONFIF FILE OPERATIONS */ |
/* CONFIF FILE OPERATIONS */ |
151 |
|
|
152 |
char *strsplit(char *, char *, char *); |
char *strsplit(char *, |
153 |
void substitute(char **inputstr, char *strin, char *strout); |
char *, |
154 |
int loadconfigfile(char *filename, int (* confighandler)(char *, char *, int, void *), void *configdata); |
char *); |
155 |
|
void substitute(char **inputstr, |
156 |
|
char *strin, |
157 |
|
char *strout); |
158 |
|
int loadconfigfile(char *filename, |
159 |
|
int (*confighandler) (char *, |
160 |
|
char *, |
161 |
|
int, |
162 |
|
void *), |
163 |
|
void *configdata); |
164 |
void *loadconfigcache(char *filename); |
void *loadconfigcache(char *filename); |
165 |
char *mktokconfstr(void *tset, int section, char *setting, char *defaul); |
char *mktokconfstr(void *tset, |
166 |
void loadintfromconfig(void *cache, int section, char *setting, int *to, int def); |
int section, |
167 |
void loadstrfromconfig(void *cache, int section, char *setting, char **to, char *def); |
char *setting, |
168 |
|
char *defaul); |
169 |
|
void loadintfromconfig(void *cache, |
170 |
|
int section, |
171 |
|
char *setting, |
172 |
|
int *to, |
173 |
|
int def); |
174 |
|
void loadstrfromconfig(void *cache, |
175 |
|
int section, |
176 |
|
char *setting, |
177 |
|
char **to, |
178 |
|
char *def); |
179 |
void freeconfigcache(void *cache); |
void freeconfigcache(void *cache); |
180 |
char **makeconfiglist(void *cache, char *section, char *label); |
char **makeconfiglist(void *cache, |
181 |
|
char *section, |
182 |
|
char *label); |
183 |
|
|
184 |
extern NEWFILE *nfopen(char *filename); |
extern NEWFILE *nfopen(char *filename); |
185 |
extern NEWFILE *nfdopen(int fd); |
extern NEWFILE *nfdopen(int fd); |
186 |
extern char *nfgetcs(NEWFILE *file, char testchar); |
extern char *nfgetcs(NEWFILE * file, |
187 |
extern void nfclose(NEWFILE *file); |
char testchar); |
188 |
|
extern void nfclose(NEWFILE * file); |
|
extern int chkpassword(char *, char *); |
|
189 |
|
|
190 |
|
extern int chkpassword(char *, |
191 |
|
char *); |