ns_saset.c

Go to the documentation of this file.
00001 /* NickServ core functions
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  * $Id: ns_set.c 850 2005-08-07 14:52:04Z geniusdex $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 #include "encrypt.h"
00018 
00019 int do_saset(User * u);
00020 int do_saset_display(User * u, NickCore * nc, char *param);
00021 int do_saset_password(User * u, NickCore * nc, char *param);
00022 int do_saset_url(User * u, NickCore * nc, char *param);
00023 int do_saset_email(User * u, NickCore * nc, char *param);
00024 int do_saset_greet(User * u, NickCore * nc, char *param);
00025 int do_saset_icq(User * u, NickCore * nc, char *param);
00026 int do_saset_kill(User * u, NickCore * nc, char *param);
00027 int do_saset_secure(User * u, NickCore * nc, char *param);
00028 int do_saset_private(User * u, NickCore * nc, char *param);
00029 int do_saset_msg(User * u, NickCore * nc, char *param);
00030 int do_saset_hide(User * u, NickCore * nc, char *param);
00031 int do_saset_noexpire(User * u, NickAlias * nc, char *param);
00032 int do_saset_autoop(User * u, NickCore * nc, char *param);
00033 void myNickServHelp(User * u);
00034 
00041 int AnopeInit(int argc, char **argv)
00042 {
00043     Command *c;
00044 
00045     moduleAddAuthor("Anope");
00046     moduleAddVersion("$Id: ns_set.c 850 2005-08-07 14:52:04Z geniusdex $");
00047     moduleSetType(CORE);
00048 
00049     c = createCommand("SASET", do_saset, is_services_oper, -1, -1, -1,
00050                       NICK_HELP_SASET, NICK_HELP_SASET);
00051     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00052     c = createCommand("SASET DISPLAY", NULL, is_services_oper,
00053                       NICK_HELP_SASET_DISPLAY, -1, -1, -1, -1);
00054     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00055     c = createCommand("SASET PASSWORD", NULL, is_services_oper,
00056                       NICK_HELP_SASET_PASSWORD, -1, -1, -1, -1);
00057     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00058     c = createCommand("SASET URL", NULL, is_services_oper,
00059                       NICK_HELP_SASET_URL, -1, -1, -1, -1);
00060     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00061     c = createCommand("SASET EMAIL", NULL, is_services_oper,
00062                       NICK_HELP_SASET_EMAIL, -1, -1, -1, -1);
00063     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00064     c = createCommand("SASET ICQ", NULL, is_services_oper,
00065                       NICK_HELP_SASET_ICQ, -1, -1, -1, -1);
00066     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00067     c = createCommand("SASET GREET", NULL, is_services_oper,
00068                       NICK_HELP_SASET_GREET, -1, -1, -1, -1);
00069     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00070     c = createCommand("SASET KILL", NULL, is_services_oper,
00071                       NICK_HELP_SASET_KILL, -1, -1, -1, -1);
00072     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00073     c = createCommand("SASET SECURE", NULL, is_services_oper,
00074                       NICK_HELP_SASET_SECURE, -1, -1, -1, -1);
00075     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00076     c = createCommand("SASET PRIVATE", NULL, is_services_oper,
00077                       NICK_HELP_SASET_PRIVATE, -1, -1, -1, -1);
00078     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00079     c = createCommand("SASET MSG", NULL, is_services_oper,
00080                       NICK_HELP_SASET_MSG, -1, -1, -1, -1);
00081     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00082     c = createCommand("SASET HIDE", NULL, is_services_oper,
00083                       NICK_HELP_SASET_HIDE, -1, -1, -1, -1);
00084     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00085     c = createCommand("SASET NOEXPIRE", NULL, is_services_oper, -1, -1,
00086                       -1, NICK_HELP_SASET_NOEXPIRE,
00087                       NICK_HELP_SASET_NOEXPIRE);
00088     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00089     c = createCommand("SASET AUTOOP", NULL, is_services_oper, -1, -1,
00090                       -1, NICK_HELP_SASET_AUTOOP,
00091                       NICK_HELP_SASET_AUTOOP);
00092     moduleAddCommand(NICKSERV, c, MOD_UNIQUE);
00093 
00094     moduleSetNickHelp(myNickServHelp);
00095 
00096     return MOD_CONT;
00097 }
00098 
00102 void AnopeFini(void)
00103 {
00104 
00105 }
00106 
00107 
00108 
00113 void myNickServHelp(User * u)
00114 {
00115     if (is_services_oper(u))
00116         notice_lang(s_NickServ, u, NICK_HELP_CMD_SASET);
00117 }
00118 
00124 int do_saset(User * u)
00125 {
00126     char *nick = strtok(NULL, " ");
00127     char *cmd = strtok(NULL, " ");
00128     char *param = strtok(NULL, " ");
00129 
00130     NickAlias *na;
00131 
00132     if (readonly) {
00133         notice_lang(s_NickServ, u, NICK_SASET_DISABLED);
00134         return MOD_CONT;
00135     }
00136     if (!nick) {
00137         syntax_error(s_NickServ, u, "SASET", NICK_SASET_SYNTAX);
00138         return MOD_CONT;
00139     }
00140     if (!(na = findnick(nick))) {
00141         notice_lang(s_NickServ, u, NICK_SASET_BAD_NICK, nick);
00142         return MOD_CONT;
00143     }
00144 
00145     if (!param
00146         && (!cmd
00147             || (stricmp(cmd, "URL") != 0 && stricmp(cmd, "EMAIL") != 0
00148                 && stricmp(cmd, "GREET") != 0
00149                 && stricmp(cmd, "ICQ") != 0))) {
00150         syntax_error(s_NickServ, u, "SASET", NICK_SASET_SYNTAX);
00151     } else if (!na) {
00152         notice_lang(s_NickServ, u, NICK_NOT_REGISTERED, nick);
00153     } else if (na->status & NS_VERBOTEN) {
00154         notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
00155     } else if (na->nc->flags & NI_SUSPENDED) {
00156         notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
00157     } else if (stricmp(cmd, "DISPLAY") == 0) {
00158         do_saset_display(u, na->nc, param);
00159     } else if (stricmp(cmd, "PASSWORD") == 0) {
00160         do_saset_password(u, na->nc, param);
00161     } else if (stricmp(cmd, "URL") == 0) {
00162         do_saset_url(u, na->nc, param);
00163     } else if (stricmp(cmd, "EMAIL") == 0) {
00164         do_saset_email(u, na->nc, param);
00165     } else if (stricmp(cmd, "ICQ") == 0) {
00166         do_saset_icq(u, na->nc, param);
00167     } else if (stricmp(cmd, "GREET") == 0) {
00168         do_saset_greet(u, na->nc, param);
00169     } else if (stricmp(cmd, "KILL") == 0) {
00170         do_saset_kill(u, na->nc, param);
00171     } else if (stricmp(cmd, "SECURE") == 0) {
00172         do_saset_secure(u, na->nc, param);
00173     } else if (stricmp(cmd, "PRIVATE") == 0) {
00174         do_saset_private(u, na->nc, param);
00175     } else if (stricmp(cmd, "MSG") == 0) {
00176         do_saset_msg(u, na->nc, param);
00177     } else if (stricmp(cmd, "HIDE") == 0) {
00178         do_saset_hide(u, na->nc, param);
00179     } else if (stricmp(cmd, "NOEXPIRE") == 0) {
00180         do_saset_noexpire(u, na, param);
00181     } else if (stricmp(cmd, "AUTOOP") == 0) {
00182         do_saset_autoop(u, na->nc, param); 
00183     } else {
00184         notice_lang(s_NickServ, u, NICK_SASET_UNKNOWN_OPTION, cmd);
00185     }
00186     return MOD_CONT;
00187 }
00188 
00189 int do_saset_display(User * u, NickCore * nc, char *param)
00190 {
00191     int i;
00192     NickAlias *na;
00193 
00194     /* First check whether param is a valid nick of the group */
00195     for (i = 0; i < nc->aliases.count; i++) {
00196         na = nc->aliases.list[i];
00197         if (stricmp(na->nick, param) == 0) {
00198             param = na->nick;   /* Because case may differ */
00199             break;
00200         }
00201     }
00202 
00203     if (i == nc->aliases.count) {
00204         notice_lang(s_NickServ, u, NICK_SASET_DISPLAY_INVALID,
00205                     nc->display);
00206         return MOD_CONT;
00207     }
00208 
00209     change_core_display(nc, param);
00210     notice_lang(s_NickServ, u, NICK_SASET_DISPLAY_CHANGED, nc->display);
00211 
00212     /* Enable nick tracking if enabled */
00213     if (NSNickTracking)
00214         nsStartNickTracking(u);
00215 
00216     return MOD_CONT;
00217 }
00218 
00219 int do_saset_password(User * u, NickCore * nc, char *param)
00220 {
00221     int len = strlen(param);
00222     char tmp_pass[PASSMAX];
00223 
00224     if (NSSecureAdmins && u->na->nc != nc && nick_is_services_admin(nc)
00225         && !is_services_root(u)) {
00226         notice_lang(s_NickServ, u, PERMISSION_DENIED);
00227         return MOD_CONT;
00228     } else if (stricmp(nc->display, param) == 0
00229                || (StrictPasswords && len < 5)) {
00230         notice_lang(s_NickServ, u, MORE_OBSCURE_PASSWORD);
00231         return MOD_CONT;
00232     }
00233 
00234     if (len > PASSMAX) {
00235         len = PASSMAX;
00236         param[len] = 0;
00237         notice_lang(s_NickServ, u, PASSWORD_TRUNCATED, PASSMAX);
00238     }
00239 
00240     if (nc->pass)
00241         free(nc->pass);
00242 
00243     nc->pass = smalloc(PASSMAX);
00244 
00245     if (enc_encrypt(param, len, nc->pass, PASSMAX) < 0) {
00246         memset(param, 0, len);
00247         alog("%s: Failed to encrypt password for %s (set)", s_NickServ,
00248              nc->display);
00249         notice_lang(s_NickServ, u, NICK_SASET_PASSWORD_FAILED,
00250                     nc->display);
00251         return MOD_CONT;
00252     }
00253 
00254     memset(param, 0, len);
00255     
00256     if(enc_decrypt(nc->pass,tmp_pass,PASSMAX)==1) {
00257         notice_lang(s_NickServ, u, NICK_SASET_PASSWORD_CHANGED_TO, nc->display,
00258                     nc->pass);
00259     } else {
00260         notice_lang(s_NickServ, u, NICK_SASET_PASSWORD_CHANGED, nc->display);
00261     }
00262 
00263     alog("%s: %s!%s@%s used SASET PASSWORD on %s (e-mail: %s)", s_NickServ,
00264          u->nick, u->username, u->host, nc->display,
00265          (nc->email ? nc->email : "none"));
00266     if (WallSetpass)
00267         anope_cmd_global(s_NickServ,
00268                          "\2%s\2 used SASET PASSWORD on \2%s\2",
00269                          u->nick, nc->display);
00270     return MOD_CONT;
00271 }
00272 
00273 int do_saset_url(User * u, NickCore * nc, char *param)
00274 {
00275     if (nc->url)
00276         free(nc->url);
00277 
00278     if (param) {
00279         nc->url = sstrdup(param);
00280         notice_lang(s_NickServ, u, NICK_SASET_URL_CHANGED, nc->display,
00281                     param);
00282     } else {
00283         nc->url = NULL;
00284         notice_lang(s_NickServ, u, NICK_SASET_URL_UNSET, nc->display);
00285     }
00286     return MOD_CONT;
00287 }
00288 
00289 int do_saset_email(User * u, NickCore * nc, char *param)
00290 {
00291     if (!param && NSForceEmail) {
00292         notice_lang(s_NickServ, u, NICK_SASET_EMAIL_UNSET_IMPOSSIBLE);
00293         return MOD_CONT;
00294     } else if (NSSecureAdmins && u->na->nc != nc
00295                && nick_is_services_admin(nc)
00296                && !is_services_root(u)) {
00297         notice_lang(s_NickServ, u, PERMISSION_DENIED);
00298         return MOD_CONT;
00299     } else if (param && !MailValidate(param)) {
00300         notice_lang(s_NickServ, u, MAIL_X_INVALID, param);
00301         return MOD_CONT;
00302     }
00303 
00304     alog("%s: %s!%s@%s used SASET EMAIL on %s (e-mail: %s)", s_NickServ,
00305          u->nick, u->username, u->host, nc->display,
00306          (nc->email ? nc->email : "none"));
00307 
00308     if (nc->email)
00309         free(nc->email);
00310 
00311     if (param) {
00312         nc->email = sstrdup(param);
00313         notice_lang(s_NickServ, u, NICK_SASET_EMAIL_CHANGED, nc->display,
00314                     param);
00315     } else {
00316         nc->email = NULL;
00317         notice_lang(s_NickServ, u, NICK_SASET_EMAIL_UNSET, nc->display);
00318     }
00319     return MOD_CONT;
00320 }
00321 
00322 int do_saset_icq(User * u, NickCore * nc, char *param)
00323 {
00324     if (param) {
00325         int32 tmp = atol(param);
00326         if (tmp == 0) {
00327             notice_lang(s_NickServ, u, NICK_SASET_ICQ_INVALID, param);
00328         } else {
00329             nc->icq = tmp;
00330             notice_lang(s_NickServ, u, NICK_SASET_ICQ_CHANGED, nc->display,
00331                         param);
00332         }
00333     } else {
00334         nc->icq = 0;
00335         notice_lang(s_NickServ, u, NICK_SASET_ICQ_UNSET, nc->display);
00336     }
00337     return MOD_CONT;
00338 }
00339 
00340 int do_saset_greet(User * u, NickCore * nc, char *param)
00341 {
00342     if (nc->greet)
00343         free(nc->greet);
00344 
00345     if (param) {
00346         char buf[BUFSIZE];
00347         char *end = strtok(NULL, "");
00348 
00349         snprintf(buf, sizeof(buf), "%s%s%s", param, (end ? " " : ""),
00350                  (end ? end : ""));
00351 
00352         nc->greet = sstrdup(buf);
00353         notice_lang(s_NickServ, u, NICK_SASET_GREET_CHANGED, nc->display,
00354                     buf);
00355     } else {
00356         nc->greet = NULL;
00357         notice_lang(s_NickServ, u, NICK_SASET_GREET_UNSET, nc->display);
00358     }
00359     return MOD_CONT;
00360 }
00361 
00362 int do_saset_kill(User * u, NickCore * nc, char *param)
00363 {
00364     if (stricmp(param, "ON") == 0) {
00365         nc->flags |= NI_KILLPROTECT;
00366         nc->flags &= ~(NI_KILL_QUICK | NI_KILL_IMMED);
00367         notice_lang(s_NickServ, u, NICK_SASET_KILL_ON, nc->display);
00368     } else if (stricmp(param, "QUICK") == 0) {
00369         nc->flags |= NI_KILLPROTECT | NI_KILL_QUICK;
00370         nc->flags &= ~NI_KILL_IMMED;
00371         notice_lang(s_NickServ, u, NICK_SASET_KILL_QUICK, nc->display);
00372     } else if (stricmp(param, "IMMED") == 0) {
00373         if (NSAllowKillImmed) {
00374             nc->flags |= NI_KILLPROTECT | NI_KILL_IMMED;
00375             nc->flags &= ~NI_KILL_QUICK;
00376             notice_lang(s_NickServ, u, NICK_SASET_KILL_IMMED, nc->display);
00377         } else {
00378             notice_lang(s_NickServ, u, NICK_SASET_KILL_IMMED_DISABLED);
00379         }
00380     } else if (stricmp(param, "OFF") == 0) {
00381         nc->flags &= ~(NI_KILLPROTECT | NI_KILL_QUICK | NI_KILL_IMMED);
00382         notice_lang(s_NickServ, u, NICK_SASET_KILL_OFF, nc->display);
00383     } else {
00384         syntax_error(s_NickServ, u, "SASET KILL",
00385                      NSAllowKillImmed ? NICK_SASET_KILL_IMMED_SYNTAX :
00386                      NICK_SASET_KILL_SYNTAX);
00387     }
00388     return MOD_CONT;
00389 }
00390 
00391 int do_saset_secure(User * u, NickCore * nc, char *param)
00392 {
00393     if (stricmp(param, "ON") == 0) {
00394         nc->flags |= NI_SECURE;
00395         notice_lang(s_NickServ, u, NICK_SASET_SECURE_ON, nc->display);
00396     } else if (stricmp(param, "OFF") == 0) {
00397         nc->flags &= ~NI_SECURE;
00398         notice_lang(s_NickServ, u, NICK_SASET_SECURE_OFF, nc->display);
00399     } else {
00400         syntax_error(s_NickServ, u, "SASET SECURE",
00401                      NICK_SASET_SECURE_SYNTAX);
00402     }
00403     return MOD_CONT;
00404 }
00405 
00406 int do_saset_private(User * u, NickCore * nc, char *param)
00407 {
00408     if (stricmp(param, "ON") == 0) {
00409         nc->flags |= NI_PRIVATE;
00410         notice_lang(s_NickServ, u, NICK_SASET_PRIVATE_ON, nc->display);
00411     } else if (stricmp(param, "OFF") == 0) {
00412         nc->flags &= ~NI_PRIVATE;
00413         notice_lang(s_NickServ, u, NICK_SASET_PRIVATE_OFF, nc->display);
00414     } else {
00415         syntax_error(s_NickServ, u, "SASET PRIVATE",
00416                      NICK_SASET_PRIVATE_SYNTAX);
00417     }
00418     return MOD_CONT;
00419 }
00420 
00421 int do_saset_msg(User * u, NickCore * nc, char *param)
00422 {
00423     if (!UsePrivmsg) {
00424         notice_lang(s_NickServ, u, NICK_SASET_OPTION_DISABLED, "MSG");
00425         return MOD_CONT;
00426     }
00427 
00428     if (stricmp(param, "ON") == 0) {
00429         nc->flags |= NI_MSG;
00430         notice_lang(s_NickServ, u, NICK_SASET_MSG_ON, nc->display);
00431     } else if (stricmp(param, "OFF") == 0) {
00432         nc->flags &= ~NI_MSG;
00433         notice_lang(s_NickServ, u, NICK_SASET_MSG_OFF, nc->display);
00434     } else {
00435         syntax_error(s_NickServ, u, "SASET MSG", NICK_SASET_MSG_SYNTAX);
00436     }
00437     return MOD_CONT;
00438 }
00439 
00440 int do_saset_hide(User * u, NickCore * nc, char *param)
00441 {
00442     int flag, onmsg, offmsg;
00443 
00444     if (stricmp(param, "EMAIL") == 0) {
00445         flag = NI_HIDE_EMAIL;
00446         onmsg = NICK_SASET_HIDE_EMAIL_ON;
00447         offmsg = NICK_SASET_HIDE_EMAIL_OFF;
00448     } else if (stricmp(param, "USERMASK") == 0) {
00449         flag = NI_HIDE_MASK;
00450         onmsg = NICK_SASET_HIDE_MASK_ON;
00451         offmsg = NICK_SASET_HIDE_MASK_OFF;
00452     } else if (stricmp(param, "STATUS") == 0) {
00453         flag = NI_HIDE_STATUS;
00454         onmsg = NICK_SASET_HIDE_STATUS_ON;
00455         offmsg = NICK_SASET_HIDE_STATUS_OFF;
00456     } else if (stricmp(param, "QUIT") == 0) {
00457         flag = NI_HIDE_QUIT;
00458         onmsg = NICK_SASET_HIDE_QUIT_ON;
00459         offmsg = NICK_SASET_HIDE_QUIT_OFF;
00460     } else {
00461         syntax_error(s_NickServ, u, "SASET HIDE", NICK_SASET_HIDE_SYNTAX);
00462         return MOD_CONT;
00463     }
00464 
00465     param = strtok(NULL, " ");
00466     if (!param) {
00467         syntax_error(s_NickServ, u, "SASET HIDE", NICK_SASET_HIDE_SYNTAX);
00468     } else if (stricmp(param, "ON") == 0) {
00469         nc->flags |= flag;
00470         notice_lang(s_NickServ, u, onmsg, nc->display, s_NickServ);
00471     } else if (stricmp(param, "OFF") == 0) {
00472         nc->flags &= ~flag;
00473         notice_lang(s_NickServ, u, offmsg, nc->display, s_NickServ);
00474     } else {
00475         syntax_error(s_NickServ, u, "SASET HIDE", NICK_SASET_HIDE_SYNTAX);
00476     }
00477     return MOD_CONT;
00478 }
00479 
00480 int do_saset_noexpire(User * u, NickAlias * na, char *param)
00481 {
00482     if (!param) {
00483         syntax_error(s_NickServ, u, "SASET NOEXPIRE",
00484                      NICK_SASET_NOEXPIRE_SYNTAX);
00485         return MOD_CONT;
00486     }
00487     if (stricmp(param, "ON") == 0) {
00488         na->status |= NS_NO_EXPIRE;
00489         notice_lang(s_NickServ, u, NICK_SASET_NOEXPIRE_ON, na->nick);
00490     } else if (stricmp(param, "OFF") == 0) {
00491         na->status &= ~NS_NO_EXPIRE;
00492         notice_lang(s_NickServ, u, NICK_SASET_NOEXPIRE_OFF, na->nick);
00493     } else {
00494         syntax_error(s_NickServ, u, "SASET NOEXPIRE",
00495                      NICK_SASET_NOEXPIRE_SYNTAX);
00496     }
00497     return MOD_CONT;
00498 }
00499 
00500 int do_saset_autoop(User * u, NickCore * nc, char *param)
00501 {
00502     if (stricmp(param, "ON") == 0) {
00503         nc->flags &= ~NI_AUTOOP;
00504         notice_lang(s_NickServ, u, NICK_SASET_AUTOOP_ON, nc->display);
00505     } else if (stricmp(param, "OFF") == 0) {
00506     nc->flags |= NI_AUTOOP;
00507         notice_lang(s_NickServ, u, NICK_SASET_AUTOOP_OFF, nc->display);
00508     } else {
00509         syntax_error(s_NickServ, u, "SET AUTOOP", NICK_SASET_AUTOOP_SYNTAX);
00510     }
00511 
00512     return MOD_CONT;
00513 }
00514 
00515 
00516 /* EOF */

Generated on Sun Dec 30 09:26:47 2007 for Anope by  doxygen 1.5.1-20070107