1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/*
* CFINGERD
* Parsing routines
*
* 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 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "cfingerd.h"
#include "proto.h"
/*
* SEARCH_ILLEGAL
*
* This searches for any illegal characters in a user's name. If there are
* any found, it returns a U_ILLEGAL, otherwise it returns a 0.
*/
int search_illegal(char *str)
{
int i;
if (str != NULL) {
for (i = 0; i < strlen(str); i++)
if (str[i] == '@')
return U_FORWARD;
else if (!isalpha(str[i]) && !isdigit(str[i]) && (str[i] != '.') &&
(str[i] != '_') && (str[i] != '-') && (str[i] != ',') &&
(str[i] != '?') && (str[i] != '*') && (str[i] != '/'))
return U_ILLEGAL;
}
return 0;
}
/*
* INTERNAL_CHECK
*
* This checks the username up against an internal username template,
* for use with cfingerd testing, debugging, and/or other information
* retrieval. Please don't disable this routine - this should be
* included with all of the cfingerd distributions.
*
* Returns U_INTERNAL if the username matches an internal username,
* otherwise, it returns a 0.
*/
int internal_check(char *username)
{
int length = strlen(username);
if (!strncmp(username, "version", 7) && length == 7 &&
prog_config.config_bits3 & SHOW_CONFESSION)
return(U_INTERNAL);
else if (!strncmp(username, "help", 4) && length == 4 &&
prog_config.config_bits3 & SHOW_CONFESSION)
return(U_INTERNAL);
else if (!strncmp(username, "services", 8) && length == 8 &&
prog_config.config_bits3 & SHOW_FAKEUSER)
return(U_INTERNAL);
else if (!strncmp(username, "search", 6) &&
prog_config.config_bits2 & SHOW_SEARCHFING)
return(U_INTERNAL);
else if (((!strncmp(username, "userlist-only", 13) && length == 13)
|| (!strncmp(username, "userlist-online", 15) && length == 15))
&& (prog_config.config_bits2 & SHOW_ULISTONLY) &&
((local_finger && prog_config.local_config_bits2 & SHOW_SYSTEMLIST) ||
(!local_finger && prog_config.config_bits2 & SHOW_SYSTEMLIST)))
return(U_INTERNAL);
return(0);
}
/*
* SEARCH_FAKE
*
* Search for a fake user. Returns U_FAKEUSER if the user is fake, and
* 0 if it is not.
*/
int search_fake(char *username)
{
char *parsed;
char *cp;
if ((cp = index (username, '.')) != NULL)
*cp='\0';
if ((parsed = (char *)malloc (strlen(username)+1)) != NULL) {
memset (parsed, 0, strlen(username)+1);
strcpy (parsed, username);
}
if (cp != NULL)
*cp='.';
if (parsed != NULL) {
if (search_fake_pos(parsed) >= 0) {
free (parsed);
return(U_FAKEUSER);
}
}
if (parsed) free (parsed);
return(0);
}
/*
* PROCESS_USERNAME
*
* This is the grand-daddy of them all. This routine does all of the
* sanity checks against the username to make sure it's a legal username.
* If the username doesn't exist, it returns the proper error message
* back to the user, and skips the finger-query request altogether. Other-
* wise, it returns:
*
* U_ILLEGAL: Username was illegal in checking
* U_FORWARD: Username is a forward request (contains `@')
* U_STANDARD: Username is a standard (non-fake) username
* U_FAKEUSER: Username matches a fake user
* U_INTERNAL: Username matches an internal (defined) username
* U_USERLIST: Username is not present - it's a userlisting
*/
int process_username(char *username)
{
int ret = 0;
if ((username[0] == 13) || (username[0] == 10) ||
(username[1] == 13) || (username[1] == 10))
ret = U_USERLIST;
else if (!strncmp (username, "userlist", 8) && strlen (username) == 8)
ret = U_USERLIST;
if (ret != U_USERLIST) {
ret = search_illegal(username);
if (ret == U_FORWARD) {
printf("%s\n", prog_config.p_strings[D_FORWARD_DENY]);
fflush(stdout);
mylog(LOG_USER, "Denied forward: ", username);
exit(1);
}
if (ret == U_ILLEGAL) {
printf("Illegal character in username.\n");
fflush(stdout);
mylog(LOG_USER, "Illegal: ", username);
exit(1);
}
ret = internal_check(username);
if (ret != U_INTERNAL)
ret = search_fake(username);
if (ret == 0)
ret = U_STANDARD;
}
return(ret);
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* tab-width: 8
* End:
*/
|