1 /* login.c version 0.333 */ 2 /* all versions previous to 0.333 are completely public domain */ 3 /* all contributed code falls under the same BSD style license as */ 4 /* noted below unless the contributing author places a copyright */ 5 /* notice in their file/s. */ 6 7 8 /* 9 * * Copyright (c) 2001 David T. Stiles 10 * * All rights reserved. 11 * * 12 * * Redistribution and use in source and binary forms, with or without 13 * * modification, are permitted provided that the following conditions 14 * * are met: 15 * * 1. Redistributions of source code must retain the above copyright 16 * * notice, this list of conditions and the following disclaimer. 17 * * 2. Redistributions in binary form must reproduce the above copyright 18 * * notice, this list of conditions and the following disclaimer in the 19 * * documentation and/or other materials provided with the distribution. 20 * * 3. All advertising materials mentioning features or use of this software 21 * * must display the following acknowledgement: 22 * * This product includes software developed by David T. Stiles 23 * * 4. The name David T. Stiles may not be used to endorse or promote 24 * * products derived from this software without specific prior written 25 * * permission. 26 * * 27 * * THIS SOFTWARE IS PROVIDED BY DAVID T. STILES `AS IS'' AND ANY 28 * * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * * ARE DISCLAIMED. IN NO EVENT SHALL DAVID T. STILES BE LIABLE 31 * * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * * SUCH DAMAGE. 38 * */ 39 40 /* this code would not be possible without the patience and intelligence */ 41 /* provided by many of the people from #c/efnet. I thank all of you sincerely. */ 42 /* user stuff. ugh! */ 43 44 #include "login.h" 45 #include "bot.h" 46 47 48 extern struct message current_message; 49 50 static struct user *usr; 51 static struct user *trv; 52 static struct user *lag; 53 static long int total_users = 0; 54 55 56 57 58 void rmuser( void ) 59 { 60 int x = 0; 61 char sndmsg[MAXDATASIZE]; 62 63 /* validate user before we do what they want */ 64 65 if( valid_login( ) ) snprintf( sndmsg, MAXDATASIZE, "privmsg %s :credentials verified.", current_message.nick ); 66 else { 67 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :access denied.", current_message.nick ); 68 send_irc_message( sndmsg ); 69 return; 70 } 71 72 /* arg 4 is the user to delete */ 73 if( current_message.msgarg4[0] == '\0' ) return; 74 75 x = valid_user( current_message.msgarg4 ); 76 if( !x ) { 77 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :user: %s not found.", current_message.nick, current_message.msgarg4 ); 78 send_irc_message( sndmsg ); 79 return; 80 } 81 82 lag->next = trv->next; 83 free( trv ); 84 --total_users; 85 86 87 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :user: %s removed.", current_message.nick, current_message.msgarg4 ); 88 send_irc_message( sndmsg ); 89 saveusers( "user.list" ); 90 return; 91 } 92 93 94 95 void adduser( void ) 96 { 97 char sndmsg[MAXDATASIZE]; 98 char salt[MAXDATASIZE]; 99 char *hash; 100 101 /* validate user before we do what they want */ 102 if( valid_login( ) ) { 103 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :credentials verified.", current_message.nick ); 104 send_irc_message( sndmsg ); 105 } 106 else { 107 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :access denied.", current_message.nick ); 108 send_irc_message( sndmsg ); 109 return; 110 } 111 112 if( current_message.msgarg4[0] == '\0' ) { 113 snprintf( sndmsg, MAXDATASIZE, "PRIVMSG %s : password is invalid", current_message.nick ); 114 send_irc_message( sndmsg ); 115 return; 116 } 117 if( current_message.msgarg5[0] == '\0' ) { 118 snprintf( sndmsg, MAXDATASIZE, "PRIVMSG %s : username is invalid", current_message.nick ); 119 send_irc_message( sndmsg ); 120 return; 121 } 122 123 if( valid_user( current_message.msgarg5 ) ) { 124 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :user exists.", current_message.nick ); 125 send_irc_message( sndmsg ); 126 return; 127 } 128 129 lag->next = (struct user *)malloc( sizeof( struct user ) ); 130 trv = lag->next; 131 trv->next = NULL; 132 133 get_salt( salt ); 134 135 hash = crypt( current_message.msgarg4, salt ); 136 137 snprintf( trv->data, MAXDATASIZE, "%s %s 0", current_message.msgarg5, hash ); 138 139 ++total_users; 140 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :user: %s added.", current_message.nick, current_message.msgarg5 ); 141 send_irc_message( sndmsg ); 142 143 return; 144 } 145 146 147 148 /* returns a positive value if the user is found. */ 149 150 int valid_user( char *nickname ) 151 { 152 char checklistname[USERINFO]; 153 154 lag = usr; 155 trv = usr->next; 156 157 while( trv ){ 158 chop( trv->data, checklistname, 0, ' ' ); 159 if( strcmp( nickname, checklistname ) ) { 160 lag = trv; 161 trv = trv->next; 162 continue; 163 } 164 return 1; 165 } 166 167 return 0; 168 } 169 170 171 /*this is basically a wrapper for the two functions that verify users. */ 172 int valid_login( void ) 173 { 174 if( current_message.msgarg3[0] != '\0' ) { 175 if( !valid_user( current_message.msgarg3 ) ) return 0; 176 } 177 else { if( !valid_user( current_message.nick ) ) return 0; } 178 179 return valid_password(); 180 } 181 182 183 184 /* this is an evil function that is in place of a real user database */ 185 186 void op_people( void ) 187 { 188 char sndmsg[MAXDATASIZE]; 189 190 191 if( valid_login( ) ){ 192 snprintf( sndmsg, MAXDATASIZE, "mode #c +o %s", current_message.nick ); 193 send_irc_message( sndmsg ); 194 return; 195 } 196 197 snprintf( sndmsg, MAXDATASIZE, "privmsg %s :either your username or password is incorrect.", current_message.nick ); 198 send_irc_message( sndmsg ); 199 200 return; 201 } |