Mercurial > prosody-modules
comparison mod_auth_imap/auth_imap/sasl_imap.lib.lua @ 3763:f384669a9359
mod_auth_imap: send CRLF instead LF, in order to be compliant with RFC3501
author | andrewhotlab <andrew.hotlab@hotmail.com> |
---|---|
date | Thu, 19 Dec 2019 20:18:26 +0100 |
parents | 7dbde05b48a9 |
children | a106477f1a65 |
comparison
equal
deleted
inserted
replaced
3762:74d7e59b3511 | 3763:f384669a9359 |
---|---|
83 return false; | 83 return false; |
84 end | 84 end |
85 log("debug", "imap greeting: '%s'", line); | 85 log("debug", "imap greeting: '%s'", line); |
86 local caps = line:match("^%*%s+OK%s+(%b[])"); | 86 local caps = line:match("^%*%s+OK%s+(%b[])"); |
87 if not caps or not caps:match("^%[CAPABILITY ") then | 87 if not caps or not caps:match("^%[CAPABILITY ") then |
88 conn:send("A CAPABILITY\n"); | 88 conn:send("A CAPABILITY\r\n"); |
89 line = conn:receive("*l"); | 89 line = conn:receive("*l"); |
90 log("debug", "imap capabilities response: '%s'", line); | 90 log("debug", "imap capabilities response: '%s'", line); |
91 caps = line:match("^%*%s+CAPABILITY%s+(.*)$"); | 91 caps = line:match("^%*%s+CAPABILITY%s+(.*)$"); |
92 if not conn:receive("*l"):match("^A OK") then | 92 if not conn:receive("*l"):match("^A OK") then |
93 log("debug", "imap capabilities command failed") | 93 log("debug", "imap capabilities command failed") |
156 if not self.selected and self.mechs[mechanism] then | 156 if not self.selected and self.mechs[mechanism] then |
157 self.tag = tostring({}):match("0x(%x*)$"); | 157 self.tag = tostring({}):match("0x(%x*)$"); |
158 self.selected = mechanism; | 158 self.selected = mechanism; |
159 local selectmsg = t_concat({ self.tag, "AUTHENTICATE", mechanism }, " "); | 159 local selectmsg = t_concat({ self.tag, "AUTHENTICATE", mechanism }, " "); |
160 log("debug", "Sending %d bytes: %q", #selectmsg, selectmsg); | 160 log("debug", "Sending %d bytes: %q", #selectmsg, selectmsg); |
161 local ok, err = self.conn:send(selectmsg.."\n"); | 161 local ok, err = self.conn:send(selectmsg.."\r\n"); |
162 if not ok then | 162 if not ok then |
163 log("error", "Could not write to socket: %s", err); | 163 log("error", "Could not write to socket: %s", err); |
164 return "failure", "internal-server-error", err | 164 return "failure", "internal-server-error", err |
165 end | 165 end |
166 local line, err = self.conn:receive("*l"); | 166 local line, err = self.conn:receive("*l"); |
179 if username then self.username = username; end | 179 if username then self.username = username; end |
180 if self._append_host and self.selected == "PLAIN" then | 180 if self._append_host and self.selected == "PLAIN" then |
181 message = message:gsub("^([^%z]*%z[^%z]+)(%z[^%z]+)$", "%1@"..self.realm.."%2"); | 181 message = message:gsub("^([^%z]*%z[^%z]+)(%z[^%z]+)$", "%1@"..self.realm.."%2"); |
182 end | 182 end |
183 log("debug", "method:process(%d bytes): %q", #message, message:gsub("%z", ".")); | 183 log("debug", "method:process(%d bytes): %q", #message, message:gsub("%z", ".")); |
184 local ok, err = self.conn:send(b64(message).."\n"); | 184 local ok, err = self.conn:send(b64(message).."\r\n"); |
185 if not ok then | 185 if not ok then |
186 log("error", "Could not write to socket: %s", err); | 186 log("error", "Could not write to socket: %s", err); |
187 return "failure", "internal-server-error", err | 187 return "failure", "internal-server-error", err |
188 end | 188 end |
189 log("debug", "Sent %d bytes to socket", ok); | 189 log("debug", "Sent %d bytes to socket", ok); |