Skip to content
Snippets Groups Projects
Commit 27e3a9a5 authored by rswindell's avatar rswindell
Browse files

New function lookup_user(), a better version of the matchname() function

from sbbsecho which uses a linked-list for the cached user list. Users are
looked up by alias or real-name (alias is has higher precedence). The found
user number is returned or 0 if not-found (or other error).
parent b90f61a5
No related branches found
No related tags found
No related merge requests found
......@@ -3355,3 +3355,37 @@ BOOL DLLCALL user_set_time_property(scfg_t* scfg, unsigned user_number, const ch
}
#endif /* !NO_SOCKET_SUPPORT */
/****************************************************************************/
/* Returns user number or 0 on failure or "user not found". */
/****************************************************************************/
int lookup_user(scfg_t* cfg, link_list_t* list, const char *inname)
{
if(inname == NULL || *inname == 0)
return 0;
if(list->first == NULL) {
user_t user;
int userdat = openuserdat(cfg, /* modify */FALSE);
if(userdat < 0)
return 0;
for(user.number = 1; ;user.number++) {
if(fgetuserdat(cfg, &user, userdat) != 0)
break;
if(user.misc&DELETED)
continue;
listPushNodeData(list, &user, sizeof(user));
}
close(userdat);
}
for(list_node_t* node = listFirstNode(list); node != NULL; node = node->next) {
if(stricmp(((user_t*)node->data)->alias, inname) == 0)
return ((user_t*)node->data)->number;
}
for(list_node_t* node = listFirstNode(list); node != NULL; node = node->next) {
if(stricmp(((user_t*)node->data)->name, inname) == 0)
return ((user_t*)node->data)->number;
}
return 0;
}
......@@ -152,6 +152,8 @@ DLLEXPORT BOOL DLLCALL check_name(scfg_t*, const char* name);
DLLEXPORT BOOL DLLCALL sysop_available(scfg_t*);
DLLEXPORT BOOL DLLCALL set_sysop_availability(scfg_t*, BOOL available);
DLLEXPORT int DLLCALL lookup_user(scfg_t*, link_list_t*, const char* name);
/* Login attempt/hack tracking */
typedef struct {
union xp_sockaddr addr; /* host with consecutive failed login attempts */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment