Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

userdat.h 8.61 KB
Newer Older
1 2 3 4 5 6
/* Synchronet user data access routines (exported) */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
rswindell's avatar
rswindell committed
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#ifndef _USERDAT_H
#define _USERDAT_H

25
#include "scfgdefs.h"   /* scfg_t */
26
#include "dat_rec.h"	/* getrec/putrec prototypes */
rswindell's avatar
rswindell committed
27
#include "client.h"		/* client_t */
28
#include "link_list.h"
29 30
#include "startup.h"	/* struct login_attempt_settings */
#include "dllexport.h"
31 32 33 34 35

#ifdef __cplusplus
extern "C" {
#endif

36 37 38 39 40 41 42 43 44
DLLEXPORT int	openuserdat(scfg_t*, BOOL for_modify);
DLLEXPORT int	closeuserdat(int);
DLLEXPORT int	readuserdat(scfg_t*, unsigned user_number, char* userdat, int infile);
DLLEXPORT int	parseuserdat(scfg_t*, char* userdat, user_t*);
DLLEXPORT int	getuserdat(scfg_t*, user_t*); 	/* Fill userdat struct with user data   */
DLLEXPORT int	fgetuserdat(scfg_t*, user_t*, int file);
DLLEXPORT int	putuserdat(scfg_t*, user_t*);	/* Put userdat struct into user file	*/
DLLEXPORT int	newuserdat(scfg_t*, user_t*);	/* Create new userdat in user file */
DLLEXPORT uint	matchuser(scfg_t*, const char *str, BOOL sysop_alias); /* Checks for a username match */
45
DLLEXPORT BOOL	matchusername(scfg_t*, const char* name, const char* compare);
46
DLLEXPORT char* alias(scfg_t*, const char* name, char* buf);
47
DLLEXPORT int	putusername(scfg_t*, int number, const char* name);
48 49 50
DLLEXPORT uint	total_users(scfg_t*);
DLLEXPORT uint	lastuser(scfg_t*);
DLLEXPORT BOOL	del_lastuser(scfg_t*);
51 52 53 54
DLLEXPORT int	getage(scfg_t*, const char* birthdate);
DLLEXPORT int	getbirthmonth(scfg_t*, const char* birthdate);
DLLEXPORT int	getbirthday(scfg_t*, const char* birthdate);
DLLEXPORT int	getbirthyear(const char* birthdate);
55 56 57
DLLEXPORT char* getbirthdstr(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* getbirthmmddyy(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* getbirthddmmyy(scfg_t*, const char* birthdate, char* buf, size_t);
58 59 60
DLLEXPORT char* parse_birthdate(scfg_t*, const char* birthdate, char* out, size_t);
DLLEXPORT char* format_birthdate(scfg_t*, const char* birthdate, char* out, size_t);
DLLEXPORT const char* birthdate_format(scfg_t*);
61 62
DLLEXPORT char*	username(scfg_t*, int usernumber, char * str);
DLLEXPORT char* usermailaddr(scfg_t*, char* addr, const char* name);
63
DLLEXPORT int	opennodedat(scfg_t*);
64
DLLEXPORT int	opennodeext(scfg_t*);
65 66
DLLEXPORT int	getnodedat(scfg_t*, uint number, node_t *node, BOOL lockit, int* file);
DLLEXPORT int	putnodedat(scfg_t*, uint number, node_t *node, BOOL closeit, int file);
67
DLLEXPORT char* nodestatus(scfg_t*, node_t* node, char* buf, size_t buflen, int num);
68 69 70 71 72 73 74 75
DLLEXPORT void	printnodedat(scfg_t*, uint number, node_t* node);
DLLEXPORT int	is_user_online(scfg_t*, uint usernumber);
DLLEXPORT void	packchatpass(char *pass, node_t* node);
DLLEXPORT char* unpackchatpass(char *pass, node_t* node);
DLLEXPORT char* getsmsg(scfg_t*, int usernumber);
DLLEXPORT int	putsmsg(scfg_t*, int usernumber, char *strin);
DLLEXPORT char* getnmsg(scfg_t*, int node_num);
DLLEXPORT int	putnmsg(scfg_t*, int num, char *strin);
76
DLLEXPORT int	getnodeclient(scfg_t*, uint number, client_t*, time_t*);
77 78 79 80 81 82 83

DLLEXPORT uint	userdatdupe(scfg_t*, uint usernumber, uint offset, uint datlen, char *dat
					,BOOL del, BOOL next, void (*progress)(void*, int, int), void* cbdata);

DLLEXPORT BOOL	chk_ar(scfg_t*, uchar* str, user_t*, client_t*); /* checks access requirements */

DLLEXPORT int	getuserrec(scfg_t*, int usernumber, int start, int length, char *str);
Rob Swindell's avatar
Rob Swindell committed
84
DLLEXPORT int	putuserrec(scfg_t*, int usernumber, int start, int length, const char *str);
85 86 87 88 89
DLLEXPORT ulong	adjustuserrec(scfg_t*, int usernumber, int start, int length, long adj);
DLLEXPORT BOOL	logoutuserdat(scfg_t*, user_t*, time_t now, time_t logontime);
DLLEXPORT void	resetdailyuserdat(scfg_t*, user_t*, BOOL write);
DLLEXPORT void	subtract_cdt(scfg_t*, user_t*, long amt);
DLLEXPORT int	user_rec_len(int offset);
90
DLLEXPORT BOOL	can_user_access_dir(scfg_t*, uint dirnum, user_t*, client_t* client);
91 92 93
DLLEXPORT BOOL	can_user_access_sub(scfg_t*, uint subnum, user_t*, client_t* client);
DLLEXPORT BOOL	can_user_read_sub(scfg_t*, uint subnum, user_t*, client_t* client);
DLLEXPORT BOOL	can_user_post(scfg_t*, uint subnum, user_t*, client_t* client, uint* reason);
94 95
DLLEXPORT BOOL	can_user_upload(scfg_t*, uint dirnum, user_t*, client_t* client, uint* reason);
DLLEXPORT BOOL	can_user_download(scfg_t*, uint dirnum, user_t*, client_t* client, uint* reason);
96 97
DLLEXPORT BOOL	can_user_send_mail(scfg_t*, enum smb_net_type, uint usernumber, user_t*, uint* reason);
DLLEXPORT BOOL	is_user_subop(scfg_t*, uint subnum, user_t*, client_t* client);
98
DLLEXPORT BOOL	is_user_dirop(scfg_t*, uint dirnum, user_t*, client_t* client);
99 100 101
DLLEXPORT BOOL	is_download_free(scfg_t*, uint dirnum, user_t*, client_t* client);
DLLEXPORT BOOL	is_host_exempt(scfg_t*, const char* ip_addr, const char* host_name);
DLLEXPORT BOOL	filter_ip(scfg_t*, const char* prot, const char* reason, const char* host
102
								  ,const char* ip_addr, const char* username, const char* fname);
103

104
/* user .ini file access */
105 106 107
DLLEXPORT BOOL	user_get_property(scfg_t*, unsigned user_number, const char* section, const char* key, char* value, size_t maxlen);
DLLEXPORT BOOL	user_set_property(scfg_t*, unsigned user_number, const char* section, const char* key, const char* value);
DLLEXPORT BOOL	user_set_time_property(scfg_t*, unsigned user_number, const char* section, const char* key, time_t);
108

rswindell's avatar
rswindell committed
109
/* New-message-scan pointer functions: */
110
DLLEXPORT BOOL	newmsgs(smb_t*, time_t);
111 112 113 114
DLLEXPORT BOOL	getmsgptrs(scfg_t*, user_t*, subscan_t*, void (*progress)(void*, int, int), void* cbdata);
DLLEXPORT BOOL	putmsgptrs(scfg_t*, user_t*, subscan_t*);
DLLEXPORT BOOL	fixmsgptrs(scfg_t*, subscan_t*);
DLLEXPORT BOOL	initmsgptrs(scfg_t*, subscan_t*, unsigned days, void (*progress)(void*, int, int), void* cbdata);
rswindell's avatar
rswindell committed
115

116
/* New atomic numeric user field adjustment functions: */
117 118
DLLEXPORT BOOL	user_posted_msg(scfg_t*, user_t*, int count);
DLLEXPORT BOOL	user_sent_email(scfg_t*, user_t*, int count, BOOL feedback);
119 120
DLLEXPORT BOOL	user_downloaded(scfg_t*, user_t*, int files, off_t bytes);
DLLEXPORT BOOL	user_downloaded_file(scfg_t*, user_t*, client_t*, uint dirnum, const char* filename, off_t bytes);
121

122
DLLEXPORT BOOL	user_uploaded(scfg_t*, user_t*, int files, off_t bytes);
123 124
DLLEXPORT BOOL	user_adjust_credits(scfg_t*, user_t*, long amount);
DLLEXPORT BOOL	user_adjust_minutes(scfg_t*, user_t*, long amount);
125

126
DLLEXPORT time_t gettimeleft(scfg_t*, user_t*, time_t starttime);
127

128 129 130
DLLEXPORT BOOL	check_name(scfg_t*, const char* name);
DLLEXPORT BOOL	sysop_available(scfg_t*);
DLLEXPORT BOOL	set_sysop_availability(scfg_t*, BOOL available);
131 132
DLLEXPORT BOOL	sound_muted(scfg_t*);
DLLEXPORT BOOL	set_sound_muted(scfg_t*, BOOL muted);
133

134
DLLEXPORT int	lookup_user(scfg_t*, link_list_t*, const char* name);
135

136
/* Login attempt/hack tracking */
137
typedef struct {
rswindell's avatar
rswindell committed
138
	union xp_sockaddr addr;	/* host with consecutive failed login attempts */
139
	ulong		count;	/* number of consecutive failed login attempts */
rswindell's avatar
rswindell committed
140
	ulong		dupes;	/* number of consecutive duplicate login attempts (same name and password) */
141
	time32_t	time;	/* time of last attempt */
142
	char		prot[32];	/* protocol used in last attempt */
143 144 145 146
	char		user[128];
	char		pass[128];
} login_attempt_t;

147 148 149 150 151 152 153 154
DLLEXPORT link_list_t*		loginAttemptListInit(link_list_t*);
DLLEXPORT BOOL				loginAttemptListFree(link_list_t*);
DLLEXPORT long				loginAttemptListCount(link_list_t*);
DLLEXPORT long				loginAttemptListClear(link_list_t*);
DLLEXPORT long				loginAttempts(link_list_t*, const union xp_sockaddr*);
DLLEXPORT void				loginSuccess(link_list_t*, const union xp_sockaddr*);
DLLEXPORT ulong				loginFailure(link_list_t*, const union xp_sockaddr*, const char* prot, const char* user, const char* pass);
DLLEXPORT ulong				loginBanned(scfg_t*, link_list_t*, SOCKET, const char* host_name, struct login_attempt_settings, login_attempt_t*);
155

156 157 158 159
#ifdef __cplusplus
}
#endif

160
#endif