Commit ea55eed9 ea55eed92d9cf235ce78fd1e8a8c869673feb0fe by Sergey Poznyakoff

Updated for GSASL >=0.2.3. Previous versions won't work.

1 parent a5fb7869
...@@ -110,7 +110,7 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize, ...@@ -110,7 +110,7 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize,
110 struct _gsasl_stream *s = stream_get_owner (stream); 110 struct _gsasl_stream *s = stream_get_owner (stream);
111 int rc; 111 int rc;
112 size_t len, sz; 112 size_t len, sz;
113 char *bufp; 113 char *bufp = NULL;
114 114
115 if (_auth_lb_level (s->lb)) 115 if (_auth_lb_level (s->lb))
116 { 116 {
...@@ -131,38 +131,28 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize, ...@@ -131,38 +131,28 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize,
131 if (status == EINTR) 131 if (status == EINTR)
132 continue; 132 continue;
133 else if (status) 133 else if (status)
134 {
135 free (bufp);
134 return status; 136 return status;
135 137 }
136 rc = _auth_lb_grow (s->lb, buf, sz); 138 rc = _auth_lb_grow (s->lb, buf, sz);
137 if (rc) 139 if (rc)
138 return rc; 140 return rc;
139 141
140 len = UINT_MAX; /* override the bug in libgsasl */
141 rc = gsasl_decode (s->sess_ctx, 142 rc = gsasl_decode (s->sess_ctx,
142 _auth_lb_data (s->lb), 143 _auth_lb_data (s->lb),
143 _auth_lb_level (s->lb), 144 _auth_lb_level (s->lb),
144 NULL, &len); 145 &bufp, &len);
145 } 146 }
146 while (rc == GSASL_NEEDS_MORE); 147 while (rc == GSASL_NEEDS_MORE);
147 148
148 if (rc != GSASL_OK) 149 if (rc != GSASL_OK)
149 { 150 {
150 s->last_err = rc; 151 s->last_err = rc;
152 free (bufp);
151 return EIO; 153 return EIO;
152 } 154 }
153 155
154 bufp = malloc (len + 1);
155 if (!bufp)
156 return ENOMEM;
157 rc = gsasl_decode (s->sess_ctx,
158 _auth_lb_data (s->lb), _auth_lb_level (s->lb), bufp, &len);
159 if (rc != GSASL_OK)
160 {
161 s->last_err = rc;
162 return EIO;
163 }
164 bufp[len++] = '\0';
165
166 sz = len > osize ? osize : len; 156 sz = len > osize ? osize : len;
167 157
168 if (len > osize) 158 if (len > osize)
...@@ -178,6 +168,9 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize, ...@@ -178,6 +168,9 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize,
178 memcpy (optr, bufp, len); 168 memcpy (optr, bufp, len);
179 } 169 }
180 170
171 if (len < osize)
172 optr[len] = 0;
173
181 if (nbytes) 174 if (nbytes)
182 *nbytes = len; 175 *nbytes = len;
183 176
...@@ -191,17 +184,11 @@ write_chunk (void *data, char *start, char *end) ...@@ -191,17 +184,11 @@ write_chunk (void *data, char *start, char *end)
191 { 184 {
192 struct _gsasl_stream *s = data; 185 struct _gsasl_stream *s = data;
193 size_t chunk_size = end - start + 1; 186 size_t chunk_size = end - start + 1;
194 size_t len; 187 size_t len = 0;
195 char *buf = NULL; 188 char *buf = NULL;
196 int status; 189 int status;
197 190
198 len = UINT_MAX; /* override the bug in libgsasl */ 191 gsasl_encode (s->sess_ctx, start, chunk_size, &buf, &len);
199 gsasl_encode (s->sess_ctx, start, chunk_size, NULL, &len);
200 buf = malloc (len);
201 if (!buf)
202 return ENOMEM;
203
204 gsasl_encode (s->sess_ctx, start, chunk_size, buf, &len);
205 192
206 status = stream_sequential_write (s->stream, buf, len); 193 status = stream_sequential_write (s->stream, buf, len);
207 194
......