[srvx-commits] CVS: services/src nickserv.c,1.189,1.190 nickserv.h,1.36,1.37 proto-bahamut.c,1.11,1.
Brought to you by:
entrope
|
From: Zoot <zo...@us...> - 2002-08-08 00:11:18
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv16975/src
Modified Files:
nickserv.c nickserv.h proto-bahamut.c proto-p10.c proto.h
Log Message:
Support ACCOUNT stamping for the P10 protocol (works with ircu 2.10.11 and lain 1.2) so users who authenticate to services stay authenticated until they quit regardless of server splits and services restarts.
Index: nickserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/nickserv.c,v
retrieving revision 1.189
retrieving revision 1.190
diff -C2 -r1.189 -r1.190
*** nickserv.c 7 Aug 2002 03:02:18 -0000 1.189
--- nickserv.c 8 Aug 2002 00:11:15 -0000 1.190
***************
*** 249,252 ****
--- 249,253 ----
static struct service *nickserv_service;
static dict_t nickserv_handle_dict; /* contains struct handle_info* */
+ static dict_t nickserv_id_dict; /* contains struct handle_info* */
static dict_t nickserv_nick_dict; /* contains struct nick_info* */
static dict_t nickserv_opt_dict; /* contains option_func_t* */
***************
*** 311,316 ****
{
struct handle_info *hi;
! /* Assign a unique account ID to the account. */
if (!id) {
id = 1 + highest_id++;
--- 312,319 ----
{
struct handle_info *hi;
+ char id_base64[IDLEN + 1];
! /* Assign a unique account ID to the account; note that 0 is
! an invalid account ID. 1 is therefore the first account ID. */
if (!id) {
id = 1 + highest_id++;
***************
*** 323,326 ****
--- 326,339 ----
}
}
+ inttobase64(id_base64, id, IDLEN);
+
+ #ifndef NDEBUG
+ /* Make sure an account with the same ID doesn't exist. This is
+ truly impossible, but it never hurts to expect it. */
+ if ((hi = dict_find(nickserv_id_dict, id_base64, NULL))) {
+ log(NS_LOG, LOG_WARNING, "Duplicated account ID %lu (%s) found belonging to %s while inserting %s.\n", id, id_base64, hi->handle, handle);
+ }
+ #endif
+
hi = calloc(1, sizeof(*hi));
hi->id = id;
***************
*** 331,334 ****
--- 344,348 ----
hi->infoline = NULL;
dict_insert(nickserv_handle_dict, hi->handle, hi);
+ dict_insert(nickserv_id_dict, strdup(id_base64), hi);
return hi;
}
***************
*** 404,407 ****
--- 418,422 ----
struct userNode *un, *next;
struct handle_info *hi = vhi;
+ char id[IDLEN + 1];
free_string_list(hi->masks);
***************
*** 411,414 ****
--- 426,431 ----
un->next_authed = NULL;
}
+ inttobase64(id, hi->id, IDLEN);
+ dict_remove(nickserv_id_dict, id);
while (hi->nicks) delete_nick(hi->nicks);
if (hi->infoline) free(hi->infoline);
***************
*** 705,709 ****
static void
! set_user_handle_info(struct userNode *user, struct handle_info *hi)
{
unsigned int n;
--- 722,726 ----
static void
! set_user_handle_info(struct userNode *user, struct handle_info *hi, int stamp)
{
unsigned int n;
***************
*** 745,749 ****
--- 762,775 ----
hi->lastseen = now;
if (IsHelper(user)) userList_append(&curr_helpers, user);
+
+ if (stamp) {
+ char id[IDLEN + 1];
+
+ /* Stamp the user with an account ID. */
+ inttobase64(id, hi->id, IDLEN);
+ irc_account(user, id);
+ }
} else {
+ /* We cannot clear the user's account ID, unfortunately. */
user->next_authed = NULL;
}
***************
*** 775,779 ****
hi->lastseen = now;
hi->flags = HI_DEFAULT_FLAGS;
! if (settee) set_user_handle_info(settee, hi);
if (nickserv_conf.disable_nicks || (user != settee)) {
--- 801,805 ----
hi->lastseen = now;
hi->flags = HI_DEFAULT_FLAGS;
! if (settee) set_user_handle_info(settee, hi, 1);
if (nickserv_conf.disable_nicks || (user != settee)) {
***************
*** 1347,1351 ****
if (hi->passwd[0] != '$') cryptpass(passwd, hi->passwd);
! set_user_handle_info(user, hi);
nickserv_notice(user, NSMSG_AUTH_SUCCESS);
return 1;
--- 1373,1377 ----
if (hi->passwd[0] != '$') cryptpass(passwd, hi->passwd);
! set_user_handle_info(user, hi, 1);
nickserv_notice(user, NSMSG_AUTH_SUCCESS);
return 1;
***************
*** 1486,1494 ****
case ACTIVATION:
safestrncpy(hi->passwd, hi->cookie->data, sizeof(hi->passwd));
! set_user_handle_info(user, hi);
nickserv_notice(user, NSMSG_HANDLE_ACTIVATED);
break;
case PASSWORD_CHANGE:
! set_user_handle_info(user, hi);
safestrncpy(hi->passwd, hi->cookie->data, sizeof(hi->passwd));
nickserv_notice(user, NSMSG_PASSWORD_CHANGED);
--- 1512,1520 ----
case ACTIVATION:
safestrncpy(hi->passwd, hi->cookie->data, sizeof(hi->passwd));
! set_user_handle_info(user, hi, 1);
nickserv_notice(user, NSMSG_HANDLE_ACTIVATED);
break;
case PASSWORD_CHANGE:
! set_user_handle_info(user, hi, 1);
safestrncpy(hi->passwd, hi->cookie->data, sizeof(hi->passwd));
nickserv_notice(user, NSMSG_PASSWORD_CHANGED);
***************
*** 1499,1503 ****
break;
case ALLOWAUTH:
! set_user_handle_info(user, hi);
nickserv_notice(user, NSMSG_AUTH_SUCCESS);
break;
--- 1525,1529 ----
break;
case ALLOWAUTH:
! set_user_handle_info(user, hi, 1);
nickserv_notice(user, NSMSG_AUTH_SUCCESS);
break;
***************
*** 3087,3090 ****
--- 3113,3136 ----
void
+ handle_account(struct userNode *user, char *stamp)
+ {
+ struct handle_info *hi;
+
+ hi = dict_find(nickserv_id_dict, stamp, NULL);
+ if (hi) {
+ /* valid_user_for() is theoretically unnecessary here
+ because users must authenticate to receive a stamp
+ in the first place; however, we must prevent
+ stamped users from getting onto suspended handles.
+ The last argument is 0 because we don't want to
+ stamp the user again. */
+ if (HANDLE_FLAGGED(hi, SUSPENDED)) {
+ return;
+ }
+ set_user_handle_info(user, hi, 0);
+ }
+ }
+
+ void
handle_nick_change(struct userNode *user, const char *new_nick)
{
***************
*** 3109,3113 ****
if (user->auth_policer) policer_delete(user->auth_policer);
dict_remove(nickserv_allow_auth_dict, user->nick);
! set_user_handle_info(user, NULL);
}
--- 3155,3159 ----
if (user->auth_policer) policer_delete(user->auth_policer);
dict_remove(nickserv_allow_auth_dict, user->nick);
! set_user_handle_info(user, NULL, 0);
}
***************
*** 3165,3168 ****
--- 3211,3215 ----
reg_nick_change_func(handle_nick_change);
reg_del_user_func(nickserv_remove_user);
+ reg_account_func(handle_account);
/* set up handle_inverse_flags */
***************
*** 3242,3245 ****
--- 3289,3295 ----
nickserv_handle_dict = dict_new();
dict_set_free_data(nickserv_handle_dict, free_handle_info);
+
+ nickserv_id_dict = dict_new();
+ dict_set_free_keys(nickserv_id_dict, free);
nickserv_nick_dict = dict_new();
Index: nickserv.h
===================================================================
RCS file: /cvsroot/srvx/services/src/nickserv.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -r1.36 -r1.37
*** nickserv.h 7 Aug 2002 03:02:18 -0000 1.36
--- nickserv.h 8 Aug 2002 00:11:15 -0000 1.37
***************
*** 27,30 ****
--- 27,33 ----
#define COOKIELEN 10
+ /* IDLEN is 6 because it takes 5.33 Base64 digits to store 32 bytes. */
+ #define IDLEN 6
+
/* HI_FLAG_* go into handle_info.flags */
#define HI_FLAG_OPER_SUSPENDED 0x00000001
Index: proto-bahamut.c
===================================================================
RCS file: /cvsroot/srvx/services/src/proto-bahamut.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** proto-bahamut.c 5 Aug 2002 03:22:19 -0000 1.11
--- proto-bahamut.c 8 Aug 2002 00:11:15 -0000 1.12
***************
*** 35,38 ****
--- 35,40 ----
};
+ static account_func_t account_func = NULL;
+
static dict_t service_msginfo_dict; /* holds service_message_info structs */
static int uplink_capab;
***************
*** 230,233 ****
--- 232,242 ----
void
+ irc_account(struct userNode *user, const char *stamp)
+ {
+ /* ACCOUNT: NOOP on Bahamut until I look at it. -- Zoot */
+ (void)user;(void)stamp;
+ }
+
+ void
irc_nick(struct userNode *user, const char *new_nick) {
if (user->uplink == self) {
***************
*** 281,286 ****
void
! irc_pong(const char *data) {
! putsock("PONG %s :%s", self->name, data);
}
--- 290,295 ----
void
! irc_pong(const char *who, const char *data) {
! putsock(":%s PONG %s :%s", self->name, who, data);
}
***************
*** 660,665 ****
static CMD_FUNC(cmd_ping)
{
! (void)argv;(void)argc;
! irc_pong(origin);
timeq_del(0, timed_send_ping, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
timeq_del(0, timed_ping_timeout, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
--- 669,673 ----
static CMD_FUNC(cmd_ping)
{
! irc_pong(self->name, argc > 1 ? argv[1] : origin);
timeq_del(0, timed_send_ping, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
timeq_del(0, timed_ping_timeout, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
***************
*** 1049,1051 ****
--- 1057,1068 ----
}
info->on_notice = handler;
+ }
+
+ void
+ reg_account_func(account_func_t handler)
+ {
+ if (account_func) {
+ log(DEBUG_LOG, LOG_WARNING, "Reregistering ACCOUNT handler.\n");
+ }
+ account_func = handler;
}
Index: proto-p10.c
===================================================================
RCS file: /cvsroot/srvx/services/src/proto-p10.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** proto-p10.c 6 Aug 2002 16:12:07 -0000 1.11
--- proto-p10.c 8 Aug 2002 00:11:15 -0000 1.12
***************
*** 21,24 ****
--- 21,25 ----
#include "proto-common.c"
+ #define CMD_ACCOUNT "ACCOUNT"
#define CMD_ADMIN "ADMIN"
#define CMD_AWAY "AWAY"
***************
*** 88,91 ****
--- 89,93 ----
#define CMD_WHOWAS "WHOWAS"
+ #define TOK_ACCOUNT "AC"
#define TOK_ADMIN "AD"
#define TOK_AWAY "A"
***************
*** 167,170 ****
--- 169,174 ----
static unsigned int num_notice_funcs = 0;
+ static account_func_t account_func = NULL;
+
static struct userNode *AddUser(struct server* uplink, const char *nick, const char *ident, const char *hostname, const char *modes, const char *numeric, const char *userinfo, time_t timestamp, const char *realip);
***************
*** 282,285 ****
--- 286,295 ----
void
+ irc_account(struct userNode *user, const char *stamp)
+ {
+ putsock("%s %s %s %s", self->numeric, CMD_ACCOUNT, user->numeric, stamp);
+ }
+
+ void
irc_nick(struct userNode *user, const char *new_nick)
{
***************
*** 775,779 ****
if (argv[6][0] == '+') {
if (argc < 10) return 0;
! AddUser(serv, argv[1], argv[4], argv[5], argv[6], argv[8], argv[9], (time_t)atoi(argv[3]), argv[7]);
} else {
AddUser(serv, argv[1], argv[4], argv[5], "+", argv[7], argv[8], (time_t)atoi(argv[3]), argv[6]);
--- 785,800 ----
if (argv[6][0] == '+') {
if (argc < 10) return 0;
! if (argc > 10) {
! /* The user is +r and has an ACCOUNT stamp in argv[7]. */
! user = AddUser(serv, argv[1], argv[4], argv[5], argv[6], argv[9], argv[10], (time_t)atoi(argv[3]), argv[8]);
!
! /* NickServ registers the sole account_func right now. */
! if(user && account_func)
! {
! account_func(user, argv[7]);
! }
! } else {
! AddUser(serv, argv[1], argv[4], argv[5], argv[6], argv[8], argv[9], (time_t)atoi(argv[3]), argv[7]);
! }
} else {
AddUser(serv, argv[1], argv[4], argv[5], "+", argv[7], argv[8], (time_t)atoi(argv[3]), argv[6]);
***************
*** 1354,1358 ****
{
static unsigned int next_numeric = 0;
! if (self->clients >= self->num_mask) return -1;
while (self->users[next_numeric]) {
if (++next_numeric > self->num_mask) next_numeric = 0;
--- 1375,1379 ----
{
static unsigned int next_numeric = 0;
! if (self->clients > self->num_mask) return -1;
while (self->users[next_numeric]) {
if (++next_numeric > self->num_mask) next_numeric = 0;
***************
*** 1657,1660 ****
--- 1678,1690 ----
}
notice_funcs[numeric] = handler;
+ }
+
+ void
+ reg_account_func(account_func_t handler)
+ {
+ if (account_func) {
+ log(DEBUG_LOG, LOG_WARNING, "Reregistering ACCOUNT handler.\n");
+ }
+ account_func = handler;
}
Index: proto.h
===================================================================
RCS file: /cvsroot/srvx/services/src/proto.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -r1.57 -r1.58
*** proto.h 6 Aug 2002 16:12:07 -0000 1.57
--- proto.h 8 Aug 2002 00:11:15 -0000 1.58
***************
*** 104,107 ****
--- 104,110 ----
void reg_mode_change_func(mode_change_func_t handler);
+ typedef void (*account_func_t) (struct userNode *user, char *stamp);
+ void reg_account_func(account_func_t handler);
+
#define MODE_CHANGE_MISC 0x001
#define MODE_CHANGE_OP 0x002
***************
*** 147,150 ****
--- 150,156 ----
void irc_raw(const char *what);
void irc_stats(struct userNode *from, struct server *target, char type);
+
+ /* account maintenance */
+ void irc_account(struct userNode *user, const char *stamp);
/* numeric messages */
|