Newer
Older
if(host_name != NULL
&& findstr(host_name, exempt))
return 0;
node = login_attempted(list, &client_addr);
listUnlock(list);
if(node == NULL)
return 0;
attempt = node->data;
if(((settings.tempban_threshold && (attempt->count - attempt->dupes) >= settings.tempban_threshold)
|| trashcan(cfg, attempt->user, "name")) && now < (time32_t)(attempt->time + settings.tempban_duration)) {
if(details != NULL)
*details = *attempt;
return settings.tempban_duration - (now - attempt->time);
#endif
/****************************************************************************/
/* Message-new-scan pointer/configuration functions */
/****************************************************************************/
BOOL DLLCALL getmsgptrs(scfg_t* cfg, user_t* user, subscan_t* subscan, void (*progress)(void*, int, int), void* cbdata)
{
char path[MAX_PATH+1];
uint i;
int file;
long length;
FILE* stream;
/* Initialize to configured defaults */
for(i=0;i<cfg->total_subs;i++) {
subscan[i].ptr=subscan[i].sav_ptr=0;
subscan[i].last=subscan[i].sav_last=0;
subscan[i].cfg=0xff;
if(!(cfg->sub[i]->misc&SUB_NSDEF))
subscan[i].cfg&=~SUB_CFG_NSCAN;
if(!(cfg->sub[i]->misc&SUB_SSDEF))
subscan[i].cfg&=~SUB_CFG_SSCAN;
subscan[i].sav_cfg=subscan[i].cfg;
}
if(user->number == 0)
return 0;
if(user->rest&FLAG('G'))
return initmsgptrs(cfg, subscan, cfg->guest_msgscan_init, progress, cbdata);
SAFEPRINTF2(path,"%suser/ptrs/%4.4u.ixb", cfg->data_dir, user->number);
if((stream=fnopen(&file,path,O_RDONLY))==NULL) {
if(fexist(path))
return(FALSE); /* file exists, but couldn't be opened? */
return initmsgptrs(cfg, subscan, cfg->new_msgscan_init, progress, cbdata);
}
length=(long)filelength(file);
for(i=0;i<cfg->total_subs;i++) {
if(progress != NULL)
progress(cbdata, i, cfg->total_subs);
if(length>=(cfg->sub[i]->ptridx+1)*10L) {
fseek(stream,(long)cfg->sub[i]->ptridx*10L,SEEK_SET);
fread(&subscan[i].ptr,sizeof(subscan[i].ptr),1,stream);
fread(&subscan[i].last,sizeof(subscan[i].last),1,stream);
fread(&subscan[i].cfg,sizeof(subscan[i].cfg),1,stream);
}
subscan[i].sav_ptr=subscan[i].ptr;
subscan[i].sav_last=subscan[i].last;
subscan[i].sav_cfg=subscan[i].cfg;
}
if(progress != NULL)
progress(cbdata, i, cfg->total_subs);
fclose(stream);
return(TRUE);
}
/****************************************************************************/
/* Writes to data/user/ptrs/####.ixb the msgptr array for the current user */
/* Pass usernumber value of 0 to indicate "Guest" login */
/****************************************************************************/
BOOL DLLCALL putmsgptrs(scfg_t* cfg, user_t* user, subscan_t* subscan)
{
char path[MAX_PATH+1];
ushort idx;
uint16_t scancfg;
uint i,j;
int file;
ulong length;
uint32_t l=0L;
if(user->number==0 || (user->rest&FLAG('G'))) /* Guest */
return(TRUE);
SAFEPRINTF2(path,"%suser/ptrs/%4.4u.ixb", cfg->data_dir, user->number);
if((file=nopen(path,O_WRONLY|O_CREAT))==-1) {
return(FALSE);
}
fixmsgptrs(cfg, subscan);
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
length=(ulong)filelength(file);
for(i=0;i<cfg->total_subs;i++) {
if(subscan[i].sav_ptr==subscan[i].ptr
&& subscan[i].sav_last==subscan[i].last
&& length>=((cfg->sub[i]->ptridx+1)*10UL)
&& subscan[i].sav_cfg==subscan[i].cfg)
continue;
while(filelength(file)<(long)(cfg->sub[i]->ptridx)*10) {
lseek(file,0L,SEEK_END);
idx=(ushort)(tell(file)/10);
for(j=0;j<cfg->total_subs;j++)
if(cfg->sub[j]->ptridx==idx)
break;
write(file,&l,sizeof(l));
write(file,&l,sizeof(l));
scancfg=0xff;
if(j<cfg->total_subs) {
if(!(cfg->sub[j]->misc&SUB_NSDEF))
scancfg&=~SUB_CFG_NSCAN;
if(!(cfg->sub[j]->misc&SUB_SSDEF))
scancfg&=~SUB_CFG_SSCAN;
} else /* default to scan OFF for unknown sub */
scancfg&=~(SUB_CFG_NSCAN|SUB_CFG_SSCAN);
write(file,&scancfg,sizeof(scancfg));
}
lseek(file,(long)((long)(cfg->sub[i]->ptridx)*10),SEEK_SET);
write(file,&(subscan[i].ptr),sizeof(subscan[i].ptr));
write(file,&(subscan[i].last),sizeof(subscan[i].last));
write(file,&(subscan[i].cfg),sizeof(subscan[i].cfg));
}
close(file);
if(!flength(path)) /* Don't leave 0 byte files */
remove(path);
return(TRUE);
}
/****************************************************************************/
/* Initialize new-msg-scan pointers (e.g. for new users) */
/* If 'days' is specified as 0, just set pointer to last message (faster) */
/****************************************************************************/
BOOL DLLCALL initmsgptrs(scfg_t* cfg, subscan_t* subscan, unsigned days, void (*progress)(void*, int, int), void* cbdata)
{
uint i;
smb_t smb;
idxrec_t idx;
time_t t = time(NULL) - (days * 24 * 60 * 60);
for(i=0;i<cfg->total_subs;i++) {
if(progress != NULL)
progress(cbdata, i, cfg->total_subs);
if(days == 0) {
/* This value will be "fixed" (changed to the last msg) when saving */
subscan[i].ptr = ~0;
continue;
}
ZERO_VAR(smb);
SAFEPRINTF2(smb.file,"%s%s",cfg->sub[i]->data_dir,cfg->sub[i]->code);
smb.retry_time=cfg->smb_retry_time;
smb.subnum=i;
if(smb_open(&smb) != SMB_SUCCESS)
continue;
if(days == 0)
subscan[i].ptr = smb.status.last_msg;
else if(smb_getmsgidx_by_time(&smb, &idx, t) == SMB_SUCCESS)
subscan[i].ptr = idx.number;
smb_close(&smb);
}
if(progress != NULL)
progress(cbdata, i, cfg->total_subs);
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
return TRUE;
}
/****************************************************************************/
/* Insure message new-scan pointers are within the range of the msgs in */
/* the sub-board. */
/****************************************************************************/
BOOL DLLCALL fixmsgptrs(scfg_t* cfg, subscan_t* subscan)
{
uint i;
smb_t smb;
for(i=0;i<cfg->total_subs;i++) {
if(subscan[i].ptr == 0)
continue;
if(subscan[i].sav_ptr == subscan[i].ptr)
continue;
ZERO_VAR(smb);
SAFEPRINTF2(smb.file,"%s%s",cfg->sub[i]->data_dir,cfg->sub[i]->code);
smb.retry_time=cfg->smb_retry_time;
smb.subnum=i;
if(smb_open(&smb) != SMB_SUCCESS)
continue;
if(subscan[i].ptr > smb.status.last_msg)
subscan[i].ptr = smb.status.last_msg;
if(subscan[i].last > smb.status.last_msg)
subscan[i].last = smb.status.last_msg;
static char* sysop_available_semfile(scfg_t* scfg)
{
static char semfile[MAX_PATH+1];
SAFEPRINTF(semfile, "%ssysavail.chat", scfg->ctrl_dir);
return semfile;
}
BOOL DLLCALL sysop_available(scfg_t* scfg)
{
return fexist(sysop_available_semfile(scfg));
}
BOOL DLLCALL set_sysop_availability(scfg_t* scfg, BOOL available)
{
if(available)
return ftouch(sysop_available_semfile(scfg));
return remove(sysop_available_semfile(scfg)) == 0;
}