X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fs_auth.c;h=b2102ad92835ee2fd71edf23e6b2895a1e747db5;hb=refs%2Fheads%2Fupstream;hp=924bd50ab13dcc36df46936301348155a327312d;hpb=894ccd3b8d5acb0067562d26bf72228d3e617203;p=ircu2.10.12-pk.git diff --git a/ircd/s_auth.c b/ircd/s_auth.c index 924bd50..b2102ad 100644 --- a/ircd/s_auth.c +++ b/ircd/s_auth.c @@ -141,7 +141,10 @@ typedef enum { /** Sends response \a r (from #ReportType) to client \a c. */ #define sendheader(c, r) \ - send(cli_fd(c), HeaderMessages[(r)].message, HeaderMessages[(r)].length, 0) + if(cli_connect(c)->con_ssl) \ + ssl_send_encrypt_plain(cli_connect(c)->con_ssl, HeaderMessages[(r)].message, HeaderMessages[(r)].length); \ + else \ + send(cli_fd(c), HeaderMessages[(r)].message, HeaderMessages[(r)].length, 0) /** Enumeration of IAuth connection flags. */ enum IAuthFlag @@ -213,6 +216,31 @@ static int preregister_user(struct Client *cptr); typedef int (*iauth_cmd_handler)(struct IAuth *iauth, struct Client *cli, int parc, char **params); +/** Copies a username, cleaning it in the process. + * + * @param[out] dest Destination buffer for user name. + * @param[in] src Source buffer for user name. Must be distinct from + * \a dest. + */ +void clean_username(char *dest, const char *src) +{ + int rlen = USERLEN; + char ch; + + /* First character can be ~, later characters cannot. */ + if (!IsCntrl(*src)) + { + ch = *src++; + *dest++ = IsUserChar(ch) ? ch : '_'; + rlen--; + } + while (rlen-- && !IsCntrl(ch = *src++)) + { + *dest++ = (IsUserChar(ch) && (ch != '~')) ? ch : '_'; + } + *dest = '\0'; +} + /** Set username for user associated with \a auth. * @param[in] auth Client authorization request to work on. * @return Zero if client is kept, CPTR_KILLED if client rejected. @@ -223,11 +251,9 @@ static int auth_set_username(struct AuthRequest *auth) struct User *user = cli_user(sptr); char *d; char *s; - int rlen = USERLEN; int killreason; short upper = 0; short lower = 0; - short pos = 0; short leadcaps = 0; short other = 0; short digits = 0; @@ -235,32 +261,27 @@ static int auth_set_username(struct AuthRequest *auth) char ch; char last; - if (FlagHas(&auth->flags, AR_IAUTH_USERNAME)) + if (FlagHas(&auth->flags, AR_IAUTH_FUSERNAME)) { - ircd_strncpy(cli_user(sptr)->username, cli_username(sptr), USERLEN); + ircd_strncpy(user->username, cli_username(sptr), USERLEN); } - else + else if (IsIdented(sptr)) { - /* Copy username from source to destination. Since they may be the - * same, and we may prefix with a '~', use a buffer character (ch) - * to hold the next character to copy. - */ - s = IsIdented(sptr) ? cli_username(sptr) : user->username; - last = *s++; - d = user->username; - if (HasFlag(sptr, FLAG_DOID) && !IsIdented(sptr)) - { - *d++ = '~'; - --rlen; - } - while (last && !IsCntrl(last) && rlen--) + clean_username(user->username, cli_username(sptr)); + } + else if (HasFlag(sptr, FLAG_DOID)) + { + /* Prepend ~ to user->username. */ + s = user->username; + s[USERLEN] = '\0'; + for (last = '~'; (ch = *s) != '\0'; ) { - ch = *s++; - *d++ = IsUserChar(last) ? last : '_'; - last = (ch != '~') ? ch : '_'; + *s++ = last; + last = ch; } - *d = 0; - } + *s++ = last; + *s = '\0'; + } /* else cleaned version of client-provided name is in place */ /* If username is empty or just ~, reject. */ if ((user->username[0] == '\0') @@ -283,7 +304,7 @@ static int auth_set_username(struct AuthRequest *auth) s = d = user->username + (user->username[0] == '~'); for (last = '\0'; (ch = *d++) != '\0'; - pos++, last = ch) + last = ch) { if (IsLower(ch)) { @@ -293,13 +314,13 @@ static int auth_set_username(struct AuthRequest *auth) { upper++; /* Accept caps as leading if we haven't seen lower case or digits yet. */ - if ((leadcaps || pos == 0) && !lower && !digits) + if ((leadcaps || last == '\0') && !lower && !digits) leadcaps++; } else if (IsDigit(ch)) { digits++; - if (pos == 0 || !IsDigit(last)) + if (!IsDigit(last)) { digitgroups++; /* If more than two groups of digits, reject. */ @@ -311,7 +332,7 @@ static int auth_set_username(struct AuthRequest *auth) { other++; /* If -_. exist at start, consecutively, or more than twice, reject. */ - if (pos == 0 || last == '-' || last == '_' || last == '.' || other > 2) + if (last == '\0' || last == '-' || last == '_' || last == '.' || other > 2) goto badid; } else /* All other punctuation is rejected. */ @@ -679,6 +700,8 @@ static void read_auth_reply(struct AuthRequest* auth) if (IsUserPort(auth->client)) sendheader(auth->client, REPORT_FAIL_ID); ++ServerStats->is_abad; + if (IAuthHas(iauth, IAUTH_UNDERNET)) + sendto_iauth(auth->client, "u"); } else { if (IsUserPort(auth->client)) sendheader(auth->client, REPORT_FIN_ID); @@ -1087,10 +1110,10 @@ int auth_set_user(struct AuthRequest *auth, const char *username, const char *ho FlagClr(&auth->flags, AR_NEEDS_USER); cptr = auth->client; ircd_strncpy(cli_info(cptr), userinfo, REALLEN); - ircd_strncpy(cli_user(cptr)->username, username, USERLEN); + clean_username(cli_user(cptr)->username, username); ircd_strncpy(cli_user(cptr)->host, cli_sockhost(cptr), HOSTLEN); if (IAuthHas(iauth, IAUTH_UNDERNET)) - sendto_iauth(cptr, "U %s %s %s :%s", username, hostname, servername, userinfo); + sendto_iauth(cptr, "U %s %s %s :%s", cli_user(cptr)->username, hostname, servername, userinfo); else if (IAuthHas(iauth, IAUTH_ADDLINFO)) sendto_iauth(cptr, "U %s", username); return check_auth_finished(auth); @@ -1373,19 +1396,19 @@ static void iauth_disconnect(struct IAuth *iauth) if (iauth == NULL) return; - /* Close main socket. */ - if (s_fd(i_socket(iauth)) != -1) { - close(s_fd(i_socket(iauth))); - socket_del(i_socket(iauth)); - s_fd(i_socket(iauth)) = -1; - } - /* Close error socket. */ if (s_fd(i_stderr(iauth)) != -1) { close(s_fd(i_stderr(iauth))); socket_del(i_stderr(iauth)); s_fd(i_stderr(iauth)) = -1; } + + /* Close main socket. */ + if (s_fd(i_socket(iauth)) != -1) { + close(s_fd(i_socket(iauth))); + socket_del(i_socket(iauth)); + s_fd(i_socket(iauth)) = -1; + } } /** Close all %IAuth connections marked as closing. */ @@ -2248,8 +2271,7 @@ static void iauth_sock_callback(struct Event *ev) switch (ev_type(ev)) { case ET_DESTROY: - /* Hm, what happened here? */ - if (!IAuthHas(iauth, IAUTH_CLOSING)) + if (!IAuthHas(iauth, IAUTH_CLOSING) && !s_active(i_stderr(iauth))) iauth_do_spawn(iauth, 1); break; case ET_READ: @@ -2322,7 +2344,8 @@ static void iauth_stderr_callback(struct Event *ev) switch (ev_type(ev)) { case ET_DESTROY: - /* We do not restart iauth here: the stdout handler does that for us. */ + if (!IAuthHas(iauth, IAUTH_CLOSING) && !s_active(i_socket(iauth))) + iauth_do_spawn(iauth, 1); break; case ET_READ: iauth_read_stderr(iauth);