Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F22791305
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/source/helpers.c b/source/helpers.c
index 5160f6c..ac518c8 100644
--- a/source/helpers.c
+++ b/source/helpers.c
@@ -1,498 +1,450 @@
/*
* Copyright (C) 1996 Darkbot Project.
* This program is free software, you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2. 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 COPYING file for details.
*/
#include "defines.h"
#include "vars.h"
#include "prototypes.h"
/**
* Add a channel helper.
* 6/22/00 Dan
* n now initialized where declared
* All pointer arguments now received as pointer to const data.
*/
void
add_helper (const char *chan,
const char *uh, long level, size_t num_join, const char *greetz, const char *pass, char mode)
{
struct helperlist *n = 0;
char *ptr = NULL;
#ifdef ENABLE_ENCRYPT
const char *salt = "8fei3k";
if ( mode == 0 )
{
if ((ptr = crypt (pass, salt)) == NULL) /* encrypt password */
return;
}
else
ptr = (char *)pass;
#else
ptr = (char *)pass;
#endif
n = malloc (sizeof (struct helperlist));
if (n == NULL)
{
db_log ("error.log", "AHHH! No ram left! in add_helper!\n");
return;
}
memset (n, 0, sizeof (struct helperlist));
NUM_HELPER++;
if (chan[0] == '#')
{
strncpy (n->chan, chan, sizeof (n->chan));
}
else
{
strncpy (n->chan, "#*", sizeof (n->chan));
}
strncpy (n->uh, uh, sizeof (n->uh));
strlwr (n->uh);
strncpy (n->pass, ptr, sizeof (n->pass));
n->num_join = num_join;
n->level = level;
strncpy (n->greetz, greetz, MIN(sizeof(n->greetz) - 1, strlen(greetz)));
n->next = helperhead;
helperhead = n;
}
/**
* Output the helper list to a nickname.
* 6/22, Dan:
* - Changed helperlist* c to be a pointer to const data
* - Changed initialization of DATA, and size to be a
* power of 2
* - Added initialization of c
* - Changed while loop to for loop
* - Changed types of i, x to size_t since they should be
* unsigned.
* - Added reinitialization of DATA using memset() (changed from
* strcpy(DATA,""))
*/
struct chanserv_output *show_helper_list(struct chanserv_output *output, const char *nick, long level)
{
char DATA [STRING_SHORT * 7] = { 0 };
char tmp [STRING_SHORT] = { 0 };
size_t i = 0, x = 0;
const struct helperlist *c = NULL;
for (c = helperhead; c != NULL; c = c->next)
{
// If we're displaying users at all levels...
if ((level == 0) || (level == c->level))
{
i++; x++;
snprintf (tmp, sizeof(tmp) - 1, "%s[%s:%ld:%d] ",
c->uh, c->chan, (long int) c->level, (int) c->num_join);
strncat(DATA, tmp, sizeof(DATA) - 1);
if (i > 6)
{
i = 0;
output = chanserv_asprintf(output, DATA);
DATA[0] = 0;
db_sleep(2);
}
}
} /* for() */
if (x != 0)
output = chanserv_asprintf(output, DATA);
output = chanserv_asprintf(output, "End of Helper Userlist; %d user%s found.", x, (x == 1) ? "" : "s");
return output;
}
void
load_helpers (void)
{
FILE *fp;
char b[STRING_LONG], *user_host, *greetz, *numb_join, *chan, *w_level, *pass;
long num_join = 0, i = 0, level = 0;
if ((fp = fopen (HELPER_LIST, "r")) == NULL)
{
printf ("Unable to open %s! Aborting connection.\n", HELPER_LIST);
printf ("Please run ./configure to setup your darkbot.\n");
exit (0);
}
printf ("Loading %s file ", HELPER_LIST);
while (fgets (b, STRING_LONG, fp))
{
if (b == NULL)
continue;
stripline (b);
if (*b == '/')
continue;
i++;
printf (".");
fflush (stdout);
chan = strtok (b, " ");
if (chan == NULL)
continue;
user_host = strtok (NULL, " ");
if (user_host == NULL)
continue;
w_level = strtok (NULL, " ");
if (w_level == NULL)
continue;
numb_join = strtok (NULL, " ");
if (numb_join == NULL)
continue;
pass = strtok (NULL, " ");
if (pass == NULL)
{
pass = "0"; /* duh */
}
greetz = strtok (NULL, "");
if (greetz == NULL)
greetz = "I haven't used \2SETINFO\2 yet!";
if (w_level != NULL)
level = atoi (w_level);
else
level = 1;
if (numb_join != NULL)
num_join = atoi (numb_join);
else
num_join = 0;
if (strlen (pass) > 25)
pass[25] = '\0';
if (DebuG == 1)
printf
("loading helperlist: %s %s l:%d j:%d %s\n",
chan, user_host, (int) level, (int) num_join, greetz);
add_helper (chan, user_host, level, num_join, greetz, pass, 1);
}
printf ("done(%d), ", (int) i);
fclose (fp);
save_changes ();
if (DebuG == 1)
db_sleep (2);
}
void
set_pass (char *nick, char *uh, char *pass, char *newpass)
{
struct helperlist *c;
char *ptr = NULL;
#ifdef ENABLE_ENCRYPT
char *salt = "8fei3k";
#endif
c = helperhead;
strlwr (uh);
#ifdef ENABLE_ENCRYPT
if ((ptr = crypt (pass, salt)) == NULL) /* encrypt old password */
return;
#else
ptr = (char *)pass;
#endif
while (c)
{
if (!match_wild (c->uh, uh) == 0)
{
if (strcmp (c->pass, ptr) == 0 || strcmp (c->pass, "0") == 0)
{
#ifdef ENABLE_ENCRYPT
if ((ptr = crypt (newpass, salt)) == NULL) /* encrypt new password */
return;
#else
ptr = (char *)newpass;
#endif
strncpy (c->pass, ptr, sizeof (c->pass));
L012 (nick, uh);
save_changes ();
return;
}
else
{
L013 (nick);
return;
}
}
c = c->next;
}
L014 (nick);
}
long
verify_pass (char *nick, char *chan, char *uh, char *pass)
{
struct helperlist *c;
char *ptr = NULL;
#ifdef ENABLE_ENCRYPT
char *salt = "8fei3k";
#endif
c = helperhead;
strlwr (uh);
#ifdef ENABLE_ENCRYPT
ptr = crypt (pass, salt)
if (ptr == NULL)
return 0;
#else
ptr = pass;
#endif
while (c)
{
if (!match_wild (c->uh, uh) == 0)
{
if (*c->pass == '0')
return 0; /* no pass set */
if (strcmp (c->pass, ptr) == 0)
{
if (has_access_for_this_channel (c->chan, chan))
{
return c->level;
}
S ("NOTICE %s :Pass verified but access is only for %s.\n", nick, c->chan);
return 0; /* don't match chan access */
}
}
c = c->next;
}
return 0;
}
int
has_access_for_this_channel (char* config_chan, char* current_chan)
{
if (config_chan[0] == '#' && config_chan[1] == '*')
return 1;
if (*current_chan == '*')
return 1;
if (strcasecmp (config_chan, current_chan) == 0)
return 1;
return 0;
}
-long
-get_pass (char *data)
-{
- /* returns 0 for no data */
- /* returns 1 for just pass */
- /* returns 2 for pass and data */
- char b[STRING_SHORT] = { 0 }, b2[STRING_SHORT] =
- {
- 0}
- , *temp = NULL;
- long i = 0;
-
- strncpy (pass_data, "0", sizeof (pass_data)); /* init */
- strncpy (pass_pass, "0", sizeof (pass_pass));
- if (data == NULL)
- return 0;
- strncpy (b2, data, sizeof (b2));
- temp = strtok (data, " ");
- if (temp == NULL)
- return -1;
- strncpy (b, temp, sizeof (b));
- while (temp != NULL)
- {
- i++;
- strncpy (pass_pass, temp, sizeof (pass_pass));
- temp = strtok (NULL, " ");
- if (temp == NULL)
- break;
- snprintf (b, sizeof (b), "%s %s", b, temp);
- }
- strncpy (b, "", sizeof (b)); /* reinit */
- temp = strtok (b2, " ");
- strncpy (b, temp, sizeof (b));
- while (i > 2)
- {
- i--;
- temp = strtok (NULL, " ");
- snprintf (b, sizeof (b), "%s %s", b, temp);
- }
- if (strcasecmp (b, pass_pass) == 0)
- {
- strncpy (pass_data, "0", sizeof (pass_data));
- return 1;
- }
- strncpy (pass_data, b, sizeof (pass_data));
- return 2;
-}
-
void
do_login (char *nick, char *pass)
{
long i = 0, x = 0, D = 0;
char Data[STRING_SHORT] = { 0 }, b[STRING_SHORT] =
{
0};
struct userlist *c;
c = userhead;
while (c)
{
if (strcasecmp (nick, c->nick) == 0)
{
x = verify_pass (c->nick, c->chan, c->uh, pass);
if (x > 0)
{
i++;
if (c->level == 0 && x >= 2)
{
#ifdef ENABLE_CHANNEL
if (OP_USERS_ON_LOGIN)
{
/* only if not already authed */
S ("MODE %s +ov %s %s\n", c->chan, c->nick, c->nick);
}
#endif
D = 1;
}
c->level = x;
snprintf (b, sizeof (b), "%s[%d] %s", c->chan, (int) c->level, Data);
strncpy (Data, b, sizeof (Data));
}
}
c = c->next;
}
if (i != 0)
{
if (!D)
{
S ("NOTICE %s :Already authed on %s\n", nick, Data);
}
else
S ("NOTICE %s :Verified: %s\n", nick, Data);
}
}
int
check_access (char *uh, char *chan, int toggle, char *nick)
{
long i = 0, length = 0, A = 0, X = 0, Y = 0;
struct helperlist *c;
struct userlist *c2;
char temp[STRING_LONG] = { 0 };
c = helperhead;
c2 = userhead;
strlwr (uh);
if (toggle == 0)
{ /* get access level */
while (c2)
{
if (strcasecmp (c2->uh, uh) == 0)
{
if (((strcasecmp (c2->chan, chan) == 0) || (strcasecmp ("#*", chan) == 0))) /* privmsg */
{
if (strcasecmp (c2->nick, nick) == 0)
{
return c2->level;
}
}
}
c2 = c2->next;
}
return 0; /* no matches? */
}
else
while (c != NULL)
{
if (!match_wild (c->uh, uh) == 0)
{
if (*c->pass == '0')
{
L001 (nick, Mynick);
return 0;
}
if (c->chan[1] != '*')
if (strcasecmp (c->chan, chan) != 0)
return 0;
c->num_join++;
if (*c->greetz == '+')
A = 1;
strncpy (data, "", sizeof (data));
length = Y = strlen (c->greetz);
if (length > 1)
{
while (length > 0)
{
length--;
X++;
if (c->greetz[length] == '^')
{
i++;
snprintf (temp, sizeof (temp), "%s%s", nick, data);
}
else if (c->greetz[length] == '%')
{
i++;
snprintf (temp, sizeof (temp), "%u%s",(unsigned int) c->num_join, data);
}
else if (c->greetz[length] == '$')
{
i++;
snprintf (temp, sizeof (temp), "%s%s", uh, data);
}
else if (c->greetz[length] == '&')
{
i++;
snprintf (temp, sizeof (temp), "%s%s", chan, data);
}
else
snprintf (temp, sizeof (temp), "%c%s", c->greetz[length], data);
if (X == Y && A == 1)
continue;
strncpy (data, temp, sizeof (data));
} /* While */
if (JOIN_GREET)
{
if (i == 0)
{
if (setinfo_lastcomm (uh) == 0)
{
S ("PRIVMSG %s :%ld\2!\2\37(\37%s\37)\37\2:\2 %s\n",
chan, c->num_join, nick, c->greetz);
}
}
else if (A == 1)
{
if (setinfo_lastcomm (uh) == 0)
{
S ("PRIVMSG %s :\1ACTION %s\1\n", chan, data);
}
}
else
{
if (setinfo_lastcomm (uh) == 0)
{
S ("PRIVMSG %s :%s\n", chan, data);
}
}
}
return c->level;
}
}
c = c->next;
}
return 0;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Feb 2, 15:26 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3410473
Default Alt Text
(10 KB)
Attached To
Mode
rDARKBOT Darkbot
Attached
Detach File
Event Timeline
Log In to Comment