Debian Codegraph @

modules/nickserv/cracklib.c

raw
1 /*
2 * Copyright (c) 2010 William Pitcock <[email protected]>
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for checking password security with cracklib.
6 */
7
8 #include "atheme.h"
9 #include "conf.h"
10 #include <sys/stat.h>
11 #include <crack.h>
12
13 DECLARE_MODULE_V1
14 (
15 "nickserv/cracklib", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 bool cracklib_warn;
21
22 static void cracklib_config_ready(void *unused)
23 {
24 module_t *m;
25 m = module_find_published("nickserv/cracklib");
26
27 if (nicksvs.cracklib_dict == NULL)
28 {
29 slog(LG_INFO, "%s requires that the cracklib_dict configuration option be set.", m->name);
30 module_unload(m, MODULE_UNLOAD_INTENT_PERM);
31 return;
32 }
33
34 hook_del_config_ready(cracklib_config_ready);
35 }
36
37 static int check_dict (char *filename)
38 {
39 struct stat sb;
40
41 if (stat(filename, &sb) == -1)
42 {
43 slog(LG_ERROR, "No cracklib dictionary found, falling back to not using a dictionary.");
44 return 0;
45 }
46 else
47 return 1;
48 }
49
50 static void
51 cracklib_hook(hook_user_register_check_t *hdata)
52 {
53 const char *cracklib_reason;
54 char dict[BUFSIZE];
55
56 mowgli_strlcpy(dict, nicksvs.cracklib_dict, BUFSIZE);
57 mowgli_strlcat(dict, ".pwd", BUFSIZE);
58
59 return_if_fail(hdata != NULL);
60 return_if_fail(hdata->si != NULL);
61 return_if_fail(hdata->password != NULL);
62
63 if ((cracklib_reason = FascistCheck(hdata->password, check_dict(dict) ? nicksvs.cracklib_dict : NULL)) != NULL)
64 {
65 if (cracklib_warn)
66 command_fail(hdata->si, fault_badparams, _("The password provided is insecure because %s. You may want to set a different password with /msg %s set password <password> ."), cracklib_reason, nicksvs.nick);
67 else
68 {
69 command_fail(hdata->si, fault_badparams, _("The password provided is insecure: %s"), cracklib_reason);
70 hdata->approved++;
71 }
72 }
73 }
74
75 static void osinfo_hook(sourceinfo_t *si)
76 {
77 return_if_fail(si != NULL);
78
79 command_success_nodata(si, "Registrations will fail with bad passwords: %s", cracklib_warn ? "No" : "Yes");
80 }
81
82 void
83 _modinit(module_t *m)
84 {
85
86 hook_add_event("user_can_register");
87 hook_add_user_can_register(cracklib_hook);
88
89 hook_add_event("config_ready");
90 hook_add_config_ready(cracklib_config_ready);
91
92 hook_add_event("operserv_info");
93 hook_add_operserv_info(osinfo_hook);
94
95 add_bool_conf_item("CRACKLIB_WARN", &nicksvs.me->conf_table, 0, &cracklib_warn, false);
96 }
97
98 void
99 _moddeinit(module_unload_intent_t intent)
100 {
101 hook_del_user_can_register(cracklib_hook);
102 hook_del_config_ready(cracklib_config_ready);
103 hook_del_operserv_info(osinfo_hook);
104
105 del_conf_item("CRACKLIB_WARN", &nicksvs.me->conf_table);
106 }