chiark / gitweb /
server: docs: remove deprecated configuration and user upgrade.
[disorder] / lib / client.c
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004-2010 Richard Kettlewell
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 /** @file lib/client.c
19  * @brief Simple C client
20  *
21  * See @ref lib/eclient.c for an asynchronous-capable client
22  * implementation.
23  */
24
25 #include "common.h"
26
27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <sys/un.h>
31 #include <unistd.h>
32 #include <errno.h>
33 #include <netdb.h>
34 #include <pcre.h>
35
36 #include "log.h"
37 #include "mem.h"
38 #include "queue.h"
39 #include "client.h"
40 #include "charset.h"
41 #include "hex.h"
42 #include "split.h"
43 #include "vector.h"
44 #include "inputline.h"
45 #include "kvp.h"
46 #include "syscalls.h"
47 #include "printf.h"
48 #include "sink.h"
49 #include "addr.h"
50 #include "authhash.h"
51 #include "client-common.h"
52 #include "rights.h"
53 #include "trackdb.h"
54 #include "kvp.h"
55
56 /** @brief Client handle contents */
57 struct disorder_client {
58   /** @brief Stream to read from */
59   FILE *fpin;
60   /** @brief Stream to write to */
61   FILE *fpout;
62   /** @brief Peer description */
63   char *ident;
64   /** @brief Username */
65   char *user;
66   /** @brief Report errors to @c stderr */
67   int verbose;
68   /** @brief Last error string */
69   const char *last;
70 };
71
72 /** @brief Create a new client
73  * @param verbose If nonzero, write extra junk to stderr
74  * @return Pointer to new client
75  *
76  * You must call disorder_connect(), disorder_connect_user() or
77  * disorder_connect_cookie() to connect it.  Use disorder_close() to
78  * dispose of the client when finished with it.
79  */
80 disorder_client *disorder_new(int verbose) {
81   disorder_client *c = xmalloc(sizeof (struct disorder_client));
82
83   c->verbose = verbose;
84   return c;
85 }
86
87 /** @brief Read a response line
88  * @param c Client
89  * @param rp Where to store response, or NULL (UTF-8)
90  * @return Response code 0-999 or -1 on error
91  */
92 static int response(disorder_client *c, char **rp) {
93   char *r;
94
95   if(inputline(c->ident, c->fpin, &r, '\n')) {
96     byte_xasprintf((char **)&c->last, "input error: %s", strerror(errno));
97     return -1;
98   }
99   D(("response: %s", r));
100   if(rp)
101     *rp = r;
102   if(r[0] >= '0' && r[0] <= '9'
103      && r[1] >= '0' && r[1] <= '9'
104      && r[2] >= '0' && r[2] <= '9'
105      && r[3] == ' ') {
106     c->last = r + 4;
107     return (r[0] * 10 + r[1]) * 10 + r[2] - 111 * '0';
108   } else {
109     c->last = "invalid reply format";
110     disorder_error(0, "invalid reply format from %s", c->ident);
111     return -1;
112   }
113 }
114
115 /** @brief Return last response string
116  * @param c Client
117  * @return Last response string (UTF-8, English) or NULL
118  */
119 const char *disorder_last(disorder_client *c) {
120   return c->last;
121 }
122
123 /** @brief Read and partially parse a response
124  * @param c Client
125  * @param rp Where to store response text (or NULL) (UTF-8)
126  * @return 0 on success, non-0 on error
127  *
128  * 5xx responses count as errors.
129  *
130  * @p rp will NOT be filled in for xx9 responses (where it is just
131  * commentary for a command where it would normally be meaningful).
132  *
133  * NB that the response will NOT be converted to the local encoding.
134  */
135 static int check_response(disorder_client *c, char **rp) {
136   int rc;
137   char *r;
138
139   if((rc = response(c, &r)) == -1)
140     return -1;
141   else if(rc / 100 == 2) {
142     if(rp)
143       *rp = (rc % 10 == 9) ? 0 : xstrdup(r + 4);
144     xfree(r);
145     return 0;
146   } else {
147     if(c->verbose)
148       disorder_error(0, "from %s: %s", c->ident, utf82mb(r));
149     xfree(r);
150     return rc;
151   }
152 }
153
154 /** @brief Issue a command and parse a simple response
155  * @param c Client
156  * @param rp Where to store result, or NULL
157  * @param cmd Command
158  * @param ap Arguments (UTF-8), terminated by (char *)0
159  * @return 0 on success, non-0 on error
160  *
161  * 5xx responses count as errors.
162  *
163  * @p rp will NOT be filled in for xx9 responses (where it is just
164  * commentary for a command where it would normally be meaningful).
165  *
166  * NB that the response will NOT be converted to the local encoding
167  * nor will quotes be stripped.  See dequote().
168  *
169  * Put @ref disorder__body in the argument list followed by a char **
170  * and int giving the body to follow the command.  If the int is @c -1
171  * then the list is assumed to be NULL-terminated.  This may be used
172  * only once.
173  *
174  * Put @ref disorder__list in the argument list followed by a char **
175  * and int giving a list of arguments to include.  If the int is @c -1
176  * then the list is assumed to be NULL-terminated.  This may be used
177  * any number of times.
178  *
179  * Put @ref disorder__integer in the argument list followed by a long to
180  * send its value in decimal.  This may be used any number of times.
181  *
182  * Put @ref disorder__time in the argument list followed by a time_t
183  * to send its value in decimal.  This may be used any number of
184  * times.
185  *
186  * Usually you would call this via one of the following interfaces:
187  * - disorder_simple()
188  */
189 static int disorder_simple_v(disorder_client *c,
190                              char **rp,
191                              const char *cmd,
192                              va_list ap) {
193   const char *arg;
194   struct dynstr d;
195   char **body = NULL;
196   int nbody = 0;
197   int has_body = 0;
198
199   if(!c->fpout) {
200     c->last = "not connected";
201     disorder_error(0, "not connected to server");
202     return -1;
203   }
204   if(cmd) {
205     dynstr_init(&d);
206     dynstr_append_string(&d, cmd);
207     while((arg = va_arg(ap, const char *))) {
208       if(arg == disorder__body) {
209         body = va_arg(ap, char **);
210         nbody = va_arg(ap, int);
211         has_body = 1;
212       } else if(arg == disorder__list) {
213         char **list = va_arg(ap, char **);
214         int nlist = va_arg(ap, int);
215         if(nlist < 0) {
216           for(nlist = 0; list[nlist]; ++nlist)
217             ;
218         }
219         for(int n = 0; n < nlist; ++n) {
220           dynstr_append(&d, ' ');
221           dynstr_append_string(&d, quoteutf8(arg));
222         }
223       } else if(arg == disorder__integer) {
224         long n = va_arg(ap, long);
225         char buffer[16];
226         snprintf(buffer, sizeof buffer, "%ld", n);
227         dynstr_append(&d, ' ');
228         dynstr_append_string(&d, buffer);
229       } else if(arg == disorder__time) {
230         time_t n = va_arg(ap, time_t);
231         char buffer[16];
232         snprintf(buffer, sizeof buffer, "%lld", (long long)n);
233         dynstr_append(&d, ' ');
234         dynstr_append_string(&d, buffer);
235       } else {
236         dynstr_append(&d, ' ');
237         dynstr_append_string(&d, quoteutf8(arg));
238       }
239     }
240     dynstr_append(&d, '\n');
241     dynstr_terminate(&d);
242     D(("command: %s", d.vec));
243     if(fputs(d.vec, c->fpout) < 0)
244       goto write_error;
245     xfree(d.vec);
246     if(has_body) {
247       if(nbody < 0)
248         for(nbody = 0; body[nbody]; ++nbody)
249           ;
250       for(int n = 0; n < nbody; ++n) {
251         if(body[n][0] == '.')
252           if(fputc('.', c->fpout) < 0)
253             goto write_error;
254         if(fputs(body[n], c->fpout) < 0)
255           goto write_error;
256         if(fputc('\n', c->fpout) < 0)
257           goto write_error;
258       }
259       if(fputs(".\n", c->fpout) < 0)
260         goto write_error;
261     }
262     if(fflush(c->fpout))
263       goto write_error;
264   }
265   return check_response(c, rp);
266 write_error:
267   byte_xasprintf((char **)&c->last, "write error: %s", strerror(errno));
268   disorder_error(errno, "error writing to %s", c->ident);
269   return -1;
270 }
271
272 /** @brief Issue a command and parse a simple response
273  * @param c Client
274  * @param rp Where to store result, or NULL (UTF-8)
275  * @param cmd Command
276  * @return 0 on success, non-0 on error
277  *
278  * The remaining arguments are command arguments, terminated by (char
279  * *)0.  They should be in UTF-8.
280  *
281  * 5xx responses count as errors.
282  *
283  * @p rp will NOT be filled in for xx9 responses (where it is just
284  * commentary for a command where it would normally be meaningful).
285  *
286  * NB that the response will NOT be converted to the local encoding
287  * nor will quotes be stripped.  See dequote().
288  */
289 static int disorder_simple(disorder_client *c,
290                            char **rp,
291                            const char *cmd, ...) {
292   va_list ap;
293   int ret;
294
295   va_start(ap, cmd);
296   ret = disorder_simple_v(c, rp, cmd, ap);
297   va_end(ap);
298   return ret;
299 }
300
301 /** @brief Issue a command and split the response
302  * @param c Client
303  * @param vecp Where to store results
304  * @param nvecp Where to store count of results
305  * @param expected Expected count (or -1 to not check)
306  * @param cmd Command
307  * @return 0 on success, non-0 on error
308  *
309  * The remaining arguments are command arguments, terminated by (char
310  * *)0.  They should be in UTF-8.
311  *
312  * 5xx responses count as errors.
313  *
314  * @p rp will NOT be filled in for xx9 responses (where it is just
315  * commentary for a command where it would normally be meaningful).
316  *
317  * NB that the response will NOT be converted to the local encoding
318  * nor will quotes be stripped.  See dequote().
319  */
320 static int disorder_simple_split(disorder_client *c,
321                                  char ***vecp,
322                                  int *nvecp,
323                                  int expected,
324                                  const char *cmd, ...) {
325   va_list ap;
326   int ret;
327   char *r;
328   char **vec;
329   int nvec;
330
331   va_start(ap, cmd);
332   ret = disorder_simple_v(c, &r, cmd, ap);
333   va_end(ap);
334   if(!ret) {
335     vec = split(r, &nvec, SPLIT_QUOTES, 0, 0);
336     xfree(r);
337     if(expected < 0 || nvec == expected) {
338       *vecp = vec;
339       *nvecp = nvec;
340     } else {
341       disorder_error(0, "malformed reply to %s", cmd);
342       c->last = "malformed reply";
343       ret = -1;
344       free_strings(nvec, vec);
345     }
346   }
347   if(ret) {
348     *vecp = NULL;
349     *nvecp = 0;
350   }
351   return ret;
352 }
353
354 /** @brief Dequote a result string
355  * @param rc 0 on success, non-0 on error
356  * @param rp Where result string is stored (UTF-8)
357  * @return @p rc
358  *
359  * This is used as a wrapper around disorder_simple() to dequote
360  * results in place.
361  */
362 static int dequote(int rc, char **rp) {
363   char **rr;
364
365   if(!rc) {
366     if((rr = split(*rp, 0, SPLIT_QUOTES, 0, 0)) && *rr) {
367       xfree(*rp);
368       *rp = *rr;
369       xfree(rr);
370       return 0;
371     }
372     disorder_error(0, "invalid reply: %s", *rp);
373   }
374   return rc;
375 }
376
377 /** @brief Generic connection routine
378  * @param conf Configuration to follow
379  * @param c Client
380  * @param username Username to log in with or NULL
381  * @param password Password to log in with or NULL
382  * @param cookie Cookie to log in with or NULL
383  * @return 0 on success, non-0 on error
384  *
385  * @p cookie is tried first if not NULL.  If it is NULL then @p
386  * username must not be.  If @p username is not NULL then nor may @p
387  * password be.
388  */
389 int disorder_connect_generic(struct config *conf,
390                              disorder_client *c,
391                              const char *username,
392                              const char *password,
393                              const char *cookie) {
394   int fd = -1, fd2 = -1, nrvec = 0, rc;
395   unsigned char *nonce = NULL;
396   size_t nl;
397   char *res = NULL;
398   char *r = NULL, **rvec = NULL;
399   const char *protocol, *algorithm, *challenge;
400   struct sockaddr *sa = NULL;
401   socklen_t salen;
402
403   if((salen = find_server(conf, &sa, &c->ident)) == (socklen_t)-1)
404     return -1;
405   c->fpin = c->fpout = 0;
406   if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
407     byte_xasprintf((char **)&c->last, "socket: %s", strerror(errno));
408     disorder_error(errno, "error calling socket");
409     return -1;
410   }
411   if(connect(fd, sa, salen) < 0) {
412     byte_xasprintf((char **)&c->last, "connect: %s", strerror(errno));
413     disorder_error(errno, "error calling connect");
414     goto error;
415   }
416   if((fd2 = dup(fd)) < 0) {
417     byte_xasprintf((char **)&c->last, "dup: %s", strerror(errno));
418     disorder_error(errno, "error calling dup");
419     goto error;
420   }
421   if(!(c->fpin = fdopen(fd, "rb"))) {
422     byte_xasprintf((char **)&c->last, "fdopen: %s", strerror(errno));
423     disorder_error(errno, "error calling fdopen");
424     goto error;
425   }
426   fd = -1;
427   if(!(c->fpout = fdopen(fd2, "wb"))) {
428     byte_xasprintf((char **)&c->last, "fdopen: %s", strerror(errno));
429     disorder_error(errno, "error calling fdopen");
430     goto error;
431   }
432   fd2 = -1;
433   if((rc = disorder_simple(c, &r, 0, (const char *)0)))
434     goto error_rc;
435   if(!(rvec = split(r, &nrvec, SPLIT_QUOTES, 0, 0)))
436     goto error;
437   if(nrvec != 3) {
438     c->last = "cannot parse server greeting";
439     disorder_error(0, "cannot parse server greeting %s", r);
440     goto error;
441   }
442   protocol = rvec[0];
443   if(strcmp(protocol, "2")) {
444     c->last = "unknown protocol version";
445     disorder_error(0, "unknown protocol version: %s", protocol);
446     goto error;
447   }
448   algorithm = rvec[1];
449   challenge = rvec[2];
450   if(!(nonce = unhex(challenge, &nl)))
451     goto error;
452   if(cookie) {
453     if(!dequote(disorder_simple(c, &c->user, "cookie", cookie, (char *)0),
454                 &c->user))
455       return 0;                         /* success */
456     if(!username) {
457       c->last = "cookie failed and no username";
458       disorder_error(0, "cookie did not work and no username available");
459       goto error;
460     }
461   }
462   if(!(res = authhash(nonce, nl, password, algorithm))) {
463     c->last = "error computing authorization hash";
464     goto error;
465   }
466   if((rc = disorder_simple(c, 0, "user", username, res, (char *)0)))
467     goto error_rc;
468   c->user = xstrdup(username);
469   xfree(res);
470   free_strings(nrvec, rvec);
471   xfree(nonce);
472   xfree(sa);
473   xfree(r);
474   return 0;
475 error:
476   rc = -1;
477 error_rc:
478   if(c->fpin) {
479     fclose(c->fpin);
480     c->fpin = 0;
481   }
482   if(c->fpout) {
483     fclose(c->fpout);
484     c->fpout = 0;
485   }
486   if(fd2 != -1) close(fd2);
487   if(fd != -1) close(fd);
488   return rc;
489 }
490
491 /** @brief Connect a client with a specified username and password
492  * @param c Client
493  * @param username Username to log in with
494  * @param password Password to log in with
495  * @return 0 on success, non-0 on error
496  */
497 int disorder_connect_user(disorder_client *c,
498                           const char *username,
499                           const char *password) {
500   return disorder_connect_generic(config,
501                                   c,
502                                   username,
503                                   password,
504                                   0);
505 }
506
507 /** @brief Connect a client
508  * @param c Client
509  * @return 0 on success, non-0 on error
510  *
511  * The connection will use the username and password found in @ref
512  * config, or directly from the database if no password is found and
513  * the database is readable (usually only for root).
514  */
515 int disorder_connect(disorder_client *c) {
516   const char *username, *password;
517
518   if(!(username = config->username)) {
519     c->last = "no username";
520     disorder_error(0, "no username configured");
521     return -1;
522   }
523   password = config->password;
524   /* Maybe we can read the database */
525   if(!password && trackdb_readable()) {
526     trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
527     trackdb_open(TRACKDB_READ_ONLY);
528     password = trackdb_get_password(username);
529     trackdb_close();
530   }
531   if(!password) {
532     /* Oh well */
533     c->last = "no password";
534     disorder_error(0, "no password configured for user '%s'", username);
535     return -1;
536   }
537   return disorder_connect_generic(config,
538                                   c,
539                                   username,
540                                   password,
541                                   0);
542 }
543
544 /** @brief Connect a client
545  * @param c Client
546  * @param cookie Cookie to log in with, or NULL
547  * @return 0 on success, non-0 on error
548  *
549  * If @p cookie is NULL or does not work then we attempt to log in as
550  * guest instead (so when the cookie expires only an extra round trip
551  * is needed rathre than a complete new login).
552  */
553 int disorder_connect_cookie(disorder_client *c,
554                             const char *cookie) {
555   return disorder_connect_generic(config,
556                                   c,
557                                   "guest",
558                                   "",
559                                   cookie);
560 }
561
562 /** @brief Close a client
563  * @param c Client
564  * @return 0 on succcess, non-0 on errior
565  *
566  * The client is still closed even on error.  It might well be
567  * appropriate to ignore the return value.
568  */
569 int disorder_close(disorder_client *c) {
570   int ret = 0;
571
572   if(c->fpin) {
573     if(fclose(c->fpin) < 0) {
574       byte_xasprintf((char **)&c->last, "fclose: %s", strerror(errno));
575       disorder_error(errno, "error calling fclose");
576       ret = -1;
577     }
578     c->fpin = 0;
579   }
580   if(c->fpout) {
581     if(fclose(c->fpout) < 0) {
582       byte_xasprintf((char **)&c->last, "fclose: %s", strerror(errno));
583       disorder_error(errno, "error calling fclose");
584       ret = -1;
585     }
586     c->fpout = 0;
587   }
588   xfree(c->ident);
589   c->ident = 0;
590   xfree(c->user);
591   c->user = 0;
592   return ret;
593 }
594
595 static void client_error(const char *msg,
596                          void attribute((unused)) *u) {
597   disorder_error(0, "error parsing reply: %s", msg);
598 }
599
600 /** @brief Get a single queue entry
601  * @param c Client
602  * @param cmd Command
603  * @param qp Where to store track information
604  * @return 0 on success, non-0 on error
605  */
606 static int onequeue(disorder_client *c, const char *cmd,
607                     struct queue_entry **qp) {
608   char *r;
609   struct queue_entry *q;
610   int rc;
611
612   if((rc = disorder_simple(c, &r, cmd, (char *)0)))
613     return rc;
614   if(r) {
615     q = xmalloc(sizeof *q);
616     if(queue_unmarshall(q, r, client_error, 0))
617       return -1;
618     *qp = q;
619   } else
620     *qp = 0;
621   return 0;
622 }
623
624 /** @brief Fetch the queue, recent list, etc */
625 static int readqueue(disorder_client *c,
626                      struct queue_entry **qp) {
627   struct queue_entry *qh, **qt = &qh, *q;
628   char *l;
629
630   while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
631     if(!strcmp(l, ".")) {
632       *qt = 0;
633       *qp = qh;
634       xfree(l);
635       return 0;
636     }
637     q = xmalloc(sizeof *q);
638     if(!queue_unmarshall(q, l, client_error, 0)) {
639       *qt = q;
640       qt = &q->next;
641     }
642     xfree(l);
643   }
644   if(ferror(c->fpin)) {
645     byte_xasprintf((char **)&c->last, "input error: %s", strerror(errno));
646     disorder_error(errno, "error reading %s", c->ident);
647   } else {
648     c->last = "input error: unexpected EOF";
649     disorder_error(0, "error reading %s: unexpected EOF", c->ident);
650   }
651   return -1;
652 }
653
654 /** @brief Read a dot-stuffed list
655  * @param c Client
656  * @param vecp Where to store list (UTF-8)
657  * @param nvecp Where to store number of items, or NULL
658  * @return 0 on success, non-0 on error
659  *
660  * The list will have a final NULL not counted in @p nvecp.
661  */
662 static int readlist(disorder_client *c, char ***vecp, int *nvecp) {
663   char *l;
664   struct vector v;
665
666   vector_init(&v);
667   while(inputline(c->ident, c->fpin, &l, '\n') >= 0) {
668     if(!strcmp(l, ".")) {
669       vector_terminate(&v);
670       if(nvecp)
671         *nvecp = v.nvec;
672       *vecp = v.vec;
673       xfree(l);
674       return 0;
675     }
676     vector_append(&v, xstrdup(l + (*l == '.')));
677     xfree(l);
678   }
679   if(ferror(c->fpin)) {
680     byte_xasprintf((char **)&c->last, "input error: %s", strerror(errno));
681     disorder_error(errno, "error reading %s", c->ident);
682   } else {
683     c->last = "input error: unexpxected EOF";
684     disorder_error(0, "error reading %s: unexpected EOF", c->ident);
685   }
686   return -1;
687 }
688
689 /** @brief Return the user we logged in with
690  * @param c Client
691  * @return User name (owned by @p c, don't modify)
692  */
693 char *disorder_user(disorder_client *c) {
694   return c->user;
695 }
696
697 static void pairlist_error_handler(const char *msg,
698                                void attribute((unused)) *u) {
699   disorder_error(0, "error handling key-value pair reply: %s", msg);
700 }
701
702 /** @brief Get a list of key-value pairs
703  * @param c Client
704  * @param kp Where to store linked list of preferences
705  * @param cmd Command
706  * @param ... Arguments
707  * @return 0 on success, non-0 on error
708  */
709 static int pairlist(disorder_client *c, struct kvp **kp, const char *cmd, ...) {
710   char **vec, **pvec;
711   int nvec, npvec, n, rc;
712   struct kvp *k;
713   va_list ap;
714
715   va_start(ap, cmd);
716   rc = disorder_simple_v(c, 0, cmd, ap);
717   va_end(ap);
718   if(rc)
719     return rc;
720   if((rc = readlist(c, &vec, &nvec)))
721      return rc;
722   for(n = 0; n < nvec; ++n) {
723     if(!(pvec = split(vec[n], &npvec, SPLIT_QUOTES, pairlist_error_handler, 0)))
724       return -1;
725     if(npvec != 2) {
726       pairlist_error_handler("malformed response", 0);
727       return -1;
728     }
729     *kp = k = xmalloc(sizeof *k);
730     k->name = pvec[0];
731     k->value = pvec[1];
732     kp = &k->next;
733     xfree(pvec);
734   }
735   free_strings(nvec, vec);
736   *kp = 0;
737   return 0;
738 }
739
740 /** @brief Parse a boolean response
741  * @param cmd Command for use in error messsage
742  * @param value Result from server
743  * @param flagp Where to store result
744  * @return 0 on success, non-0 on error
745  */
746 static int boolean(const char *cmd, const char *value,
747                    int *flagp) {
748   if(!strcmp(value, "yes")) *flagp = 1;
749   else if(!strcmp(value, "no")) *flagp = 0;
750   else {
751     disorder_error(0, "malformed response to '%s'", cmd);
752     return -1;
753   }
754   return 0;
755 }
756
757 /** @brief Log to a sink
758  * @param c Client
759  * @param s Sink to write log lines to
760  * @return 0 on success, non-0 on error
761  */
762 int disorder_log(disorder_client *c, struct sink *s) {
763   char *l;
764   int rc;
765     
766   if((rc = disorder_simple(c, 0, "log", (char *)0)))
767     return rc;
768   while(inputline(c->ident, c->fpin, &l, '\n') >= 0 && strcmp(l, "."))
769     if(sink_printf(s, "%s\n", l) < 0) return -1;
770   if(ferror(c->fpin) || feof(c->fpin)) {
771     byte_xasprintf((char **)&c->last, "input error: %s",
772                    ferror(c->fpin) ? strerror(errno) : "unexpxected EOF");
773     return -1;
774   }
775   return 0;
776 }
777
778 #include "client-stubs.c"
779
780 /*
781 Local Variables:
782 c-basic-offset:2
783 comment-column:40
784 End:
785 */