]> git.pld-linux.org Git - packages/cyrus-sasl.git/blame - cyrus-sasl-cryptedpw.patch
- allow building without Nagios support
[packages/cyrus-sasl.git] / cyrus-sasl-cryptedpw.patch
CommitLineData
b0aee5d1
JR
1diff -urNp -x '*.orig' cyrus-sasl-2.1.27.org/Makefile.in cyrus-sasl-2.1.27/Makefile.in
2--- cyrus-sasl-2.1.27.org/Makefile.in 2018-10-09 16:58:13.000000000 +0200
3+++ cyrus-sasl-2.1.27/Makefile.in 2021-09-28 23:58:30.012662863 +0200
4@@ -308,7 +308,7 @@ LDAP_LIBS = @LDAP_LIBS@
afbe97ef 5 LDFLAGS = @LDFLAGS@
b0aee5d1 6 LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@
afbe97ef 7 LIBOBJS = @LIBOBJS@
8-LIBS = @LIBS@
9+LIBS = -lcrypt @LIBS@
10 LIBTOOL = @LIBTOOL@
11 LIB_CRYPT = @LIB_CRYPT@
12 LIB_DES = @LIB_DES@
b0aee5d1
JR
13diff -urNp -x '*.orig' cyrus-sasl-2.1.27.org/doc/legacy/options.html cyrus-sasl-2.1.27/doc/legacy/options.html
14--- cyrus-sasl-2.1.27.org/doc/legacy/options.html 2017-07-24 14:53:03.000000000 +0200
15+++ cyrus-sasl-2.1.27/doc/legacy/options.html 2021-09-28 23:58:30.012662863 +0200
16@@ -163,6 +163,14 @@ database.</TD>
17 <TD>126</TD>
18 </TR>
afbe97ef 19 <TR>
20+<TD>password_format</TD><TD></TD>
21+<TD>Method of password storage (possible values: 'plain', 'crypt', 'crypt_trad').
22+Default 'plain' is down-compatible with earlier versions. 'crypt_trad'
23+uses old crypt format of 2 chars salt, 'crypt' automagically recognizes crypt
24+formats from md5 crypt, blowfish crypt and old crypt (2 chars salt).</TD>
25+<TD>plain</TD>
26+</TR>
27+<TR>
28 <TD>sql_engine</TD><TD>SQL plugin</TD>
b0aee5d1 29 <TD>Name of SQL engine to use (possible values: 'mysql', 'pgsql', 'sqlite', 'sqlite3').</TD>
afbe97ef 30 <TD><tt>mysql</tt></TD>
b0aee5d1
JR
31diff -urNp -x '*.orig' cyrus-sasl-2.1.27.org/lib/checkpw.c cyrus-sasl-2.1.27/lib/checkpw.c
32--- cyrus-sasl-2.1.27.org/lib/checkpw.c 2018-11-08 18:29:57.000000000 +0100
33+++ cyrus-sasl-2.1.27/lib/checkpw.c 2021-09-28 23:58:30.012662863 +0200
94e6777d 34@@ -95,6 +95,23 @@
afbe97ef 35 # endif
36 #endif
37
38+/******************************
39+ * crypt(3) patch start *
40+ ******************************/
41+char *crypt(const char *key, const char *salt);
42+
43+/* cleartext password formats */
44+#define PASSWORD_FORMAT_CLEARTEXT 1
45+#define PASSWORD_FORMAT_CRYPT 2
46+#define PASSWORD_FORMAT_CRYPTTRAD 3
47+#define PASSWORD_SALT_BUF_LEN 22
48+
49+/* weeds out crypt(3) password's salt */
50+int _sasl_get_salt (char *dest, char *src, int format);
51+
52+/******************************
53+ * crypt(3) patch stop *
54+ ******************************/
55
56 /* we store the following secret to check plaintext passwords:
57 *
b0aee5d1 58@@ -142,7 +159,51 @@ static int auxprop_verify_password(sasl_
afbe97ef 59 "*cmusaslsecretPLAIN",
60 NULL };
61 struct propval auxprop_values[3];
62-
63+
64+ /******************************
65+ * crypt(3) patch start *
66+ * for password format check *
67+ ******************************/
68+ sasl_getopt_t *getopt;
69+ void *context;
70+ const char *p = NULL;
71+ /**
72+ * MD5: 12 char salt
73+ * BLOWFISH: 16 char salt
74+ */
75+ char salt[PASSWORD_SALT_BUF_LEN];
76+ int password_format;
77+
78+ /* get password format from auxprop configuration */
79+ if (_sasl_getcallback(conn, SASL_CB_GETOPT, &getopt, &context) == SASL_OK) {
80+ getopt(context, NULL, "password_format", &p, NULL);
81+ }
82+
83+ /* set password format */
84+ if (p) {
85+ /*
86+ memset(pass_format_str, '\0', PASSWORD_FORMAT_STR_LEN);
87+ strncpy(pass_format_str, p, (PASSWORD_FORMAT_STR_LEN - 1));
88+ */
89+ /* modern, modular crypt(3) */
90+ if (strncmp(p, "crypt", 11) == 0)
91+ password_format = PASSWORD_FORMAT_CRYPT;
92+ /* traditional crypt(3) */
93+ else if (strncmp(p, "crypt_trad", 11) == 0)
94+ password_format = PASSWORD_FORMAT_CRYPTTRAD;
95+ /* cleartext password */
96+ else
97+ password_format = PASSWORD_FORMAT_CLEARTEXT;
98+ } else {
99+ /* cleartext password */
100+ password_format = PASSWORD_FORMAT_CLEARTEXT;
101+ }
102+
103+ /******************************
104+ * crypt(3) patch stop *
105+ * for password format check *
106+ ******************************/
107+
108 if (!conn || !userstr)
109 return SASL_BADPARAM;
110
b0aee5d1 111@@ -188,14 +249,31 @@ static int auxprop_verify_password(sasl_
94e6777d 112 return SASL_NOUSER;
afbe97ef 113 }
94e6777d 114
afbe97ef 115- /* At the point this has been called, the username has been canonified
116- * and we've done the auxprop lookup. This should be easy. */
117- if(auxprop_values[0].name
118- && auxprop_values[0].values
119- && auxprop_values[0].values[0]
120- && !strcmp(auxprop_values[0].values[0], passwd)) {
121- /* We have a plaintext version and it matched! */
122- return SASL_OK;
123+
124+ /******************************
125+ * crypt(3) patch start *
126+ ******************************/
127+
128+ /* get salt */
129+ _sasl_get_salt(salt, (char *) auxprop_values[0].values[0], password_format);
130+
131+ /* crypt(3)-ed password? */
132+ if (password_format != PASSWORD_FORMAT_CLEARTEXT) {
133+ /* compare password */
134+ if (auxprop_values[0].name && auxprop_values[0].values && auxprop_values[0].values[0] && strcmp(crypt(passwd, salt), auxprop_values[0].values[0]) == 0)
135+ return SASL_OK;
136+ else
137+ ret = SASL_BADAUTH;
138+ }
139+ else if (password_format == PASSWORD_FORMAT_CLEARTEXT) {
140+ /* compare passwords */
141+ if (auxprop_values[0].name && auxprop_values[0].values && auxprop_values[0].values[0] && strcmp(auxprop_values[0].values[0], passwd) == 0)
142+ return SASL_OK;
143+ else
144+ ret = SASL_BADAUTH;
145+ /******************************
146+ * crypt(3) patch stop *
147+ ******************************/
148 } else if(auxprop_values[1].name
149 && auxprop_values[1].values
150 && auxprop_values[1].values[0]) {
b0aee5d1 151@@ -1105,3 +1183,37 @@ struct sasl_verify_password_s _sasl_veri
94e6777d 152 #endif
afbe97ef 153 { NULL, NULL }
154 };
155+
156+/* weeds out crypt(3) password's salt */
157+int _sasl_get_salt (char *dest, char *src, int format) {
158+ int num; /* how many characters is salt long? */
159+ switch (format) {
160+ case PASSWORD_FORMAT_CRYPT:
161+ /* md5 crypt */
162+ if (src[1] == '1')
163+ num = 12;
164+ /* blowfish crypt */
165+ else if (src[1] == '2')
166+ num = (src[1] == '2' && src[2] == 'a') ? 17 : 16;
167+ /* traditional crypt */
168+ else
169+ num = 2;
170+ break;
171+
172+ case PASSWORD_FORMAT_CRYPTTRAD:
173+ num = 2;
174+ break;
175+
176+ default:
177+ return 1;
178+ }
179+
180+ /* destroy destination */
181+ memset(dest, '\0', (num + 1));
182+
183+ /* copy salt to destination */
184+ strncpy(dest, src, num);
185+
186+ return 1;
187+}
188+
This page took 0.112808 seconds and 4 git commands to generate.