1
0
forked from bip/bip

merge master

This commit is contained in:
Arnaud Cornet 2009-01-05 23:24:49 +01:00
commit 0600196102
7 changed files with 33 additions and 23 deletions

View File

@ -5,6 +5,7 @@
set -e
aclocal
autoheader
autoconf
automake --add-missing --copy -Wall

View File

@ -3,6 +3,7 @@ AM_CONFIG_HEADER(src/config.h)
AM_INIT_AUTOMAKE(bip,0.8.0)
AC_PROG_CC
AC_PROG_INSTALL
AM_PROG_LEX
AC_PROG_YACC

View File

@ -33,23 +33,23 @@ void readpass(char *buffer, int buflen)
fprintf(stderr, "Unable to open tty: %s\n", strerror(errno));
exit(1);
}
struct termios tt, ttback;
memset(&ttback, 0, sizeof(ttback));
if (tcgetattr(ttyfd, &ttback) < 0) {
printf("tcgetattr failed: %s\n", strerror(errno));
fprintf(stderr, "tcgetattr failed: %s\n", strerror(errno));
exit(1);
}
memcpy(&tt, &ttback, sizeof(ttback));
tt.c_lflag &= ~(ICANON|ECHO);
if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) {
printf("tcsetattr failed: %s\n", strerror(errno));
fprintf(stderr, "tcsetattr failed: %s\n", strerror(errno));
exit(1);
}
write(ttyfd, "Password: ", 10);
int idx = 0;
while (idx < buflen) {
read(ttyfd, buffer+idx, 1);
@ -59,9 +59,9 @@ void readpass(char *buffer, int buflen)
}
idx++;
}
write(ttyfd, "\n", 1);
tcsetattr(ttyfd, TCSANOW, &ttback);
close(ttyfd);
}
@ -74,11 +74,12 @@ int main(void)
unsigned int seed;
readpass(str, 256);
str[255] = 0;
// the time used to type the pass is entropy
srand(time(NULL));
seed = rand();
md5 = chash_double(str, seed);
for (i = 0; i < 20; i++)
printf("%02x", md5[i]);

View File

@ -36,9 +36,7 @@ list_t *root_list;
struct tuple *tuple_i_new(int type, int i)
{
struct tuple *t;
t = malloc(sizeof(struct tuple));
if (!t)
fatal("malloc");
t = bip_malloc(sizeof(struct tuple));
t->type = type;
t->ndata = i;
t->tuple_type = TUPLE_INT;
@ -48,9 +46,7 @@ struct tuple *tuple_i_new(int type, int i)
struct tuple *tuple_p_new(int type, void *p)
{
struct tuple *t;
t = malloc(sizeof(struct tuple));
if (!t)
fatal("malloc");
t = bip_malloc(sizeof(struct tuple));
t->type = type;
t->pdata = p;
return t;

View File

@ -897,8 +897,6 @@ static void create_socket(char *dsthostname, char *dstport, char *srchostname,
cn->connected = CONN_ERROR;
cdata = (struct connecting_data *)
bip_malloc(sizeof(struct connecting_data));
if (!cdata)
fatal("Out of memory.");
cdata->dst = cdata->src = cdata->cur = NULL;
err = getaddrinfo(dsthostname, dstport, &hint, &cdata->dst);

View File

@ -88,8 +88,7 @@ char *nick_from_ircmask(const char *mask)
char *ret;
size_t len;
if (!mask)
fatal("nick_from_ircmask");
assert(mask);
while (*nick && *nick != '!')
nick++;
@ -1273,9 +1272,10 @@ static int irc_join(struct link_server *server, struct line *line)
return ERR_PROTOCOL;
if (!line->origin)
return ERR_PROTOCOL;
s_nick = nick_from_ircmask(line->origin);
s_nick = nick_from_ircmask(line->origin);
hash_insert(&channel->ovmasks, s_nick, 0);
free(s_nick);
return OK_COPY;
}
@ -1490,9 +1490,12 @@ static int irc_part(struct link_server *server, struct line *line)
if (!line->origin)
return ERR_PROTOCOL;
s_nick = nick_from_ircmask(line->origin);
if (!hash_includes(&channel->ovmasks, s_nick))
if (!hash_includes(&channel->ovmasks, s_nick)) {
free(s_nick);
return ERR_PROTOCOL;
}
hash_remove(&channel->ovmasks, s_nick);
free(s_nick);
log_part(LINK(server)->log, line->origin, s_chan,
irc_line_count(line) == 3 ?
@ -2128,6 +2131,7 @@ connection_t *irc_server_connect(struct link *link)
if (conn->handle == -1) {
mylog(LOG_INFO, "Cannot connect.");
connection_free(conn);
server_next(link);
return NULL;
}

View File

@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
@ -41,7 +42,11 @@ void memory_fatal(void)
void *bip_malloc(size_t size)
{
void *r = malloc(size);
void *r;
assert(size < INT_MAX / 4);
r = malloc(size);
if (!r)
memory_fatal();
return r;
@ -57,7 +62,11 @@ void *bip_calloc(size_t nmemb, size_t size)
void *bip_realloc(void *ptr, size_t size)
{
void *r = realloc(ptr, size);
void *r;
assert(size < INT_MAX / 4);
r = realloc(ptr, size);
if (size > 0 && r == NULL)
memory_fatal();
return r;