]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_dsi.c
Better handling of connection errors and disconnect state
[netatalk.git] / etc / afpd / afp_dsi.c
1 /*
2  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
3  * Copyright (c) 1990,1993 Regents of The University of Michigan.
4  * All Rights Reserved.  See COPYRIGHT.
5  *
6  * modified from main.c. this handles afp over tcp.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif /* HAVE_CONFIG_H */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <signal.h>
16 #include <string.h>
17 #include <errno.h>
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif /* HAVE_UNISTD_H */
21 #include <sys/socket.h>
22 #include <sys/time.h>
23 #ifdef HAVE_SYS_STAT_H
24 #include <sys/stat.h>
25 #endif /* HAVE_SYS_STAT_H */
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
28 #include <atalk/logger.h>
29
30 #include <atalk/dsi.h>
31 #include <atalk/compat.h>
32 #include <atalk/util.h>
33
34 #include "globals.h"
35 #include "switch.h"
36 #include "auth.h"
37 #include "fork.h"
38 #include "dircache.h"
39
40 #ifdef FORCE_UIDGID
41 #warning UIDGID
42 #include "uid.h"
43 #endif /* FORCE_UIDGID */
44
45 /* 
46  * We generally pass this from afp_over_dsi to all afp_* funcs, so it should already be
47  * available everywhere. Unfortunately some funcs (eg acltoownermode) need acces to it
48  * but are deeply nested in the function chain with the caller already without acces to it.
49  * Changing this would require adding a reference to the caller which itself might be
50  * called in many places (eg acltoownermode is called from accessmode).
51  * The only sane way out is providing a copy of it here:
52  */
53 AFPObj *AFPobj = NULL;
54
55 static struct {
56     AFPObj *obj;
57     unsigned char flags;
58     int tickle;
59 } child;
60
61 typedef struct {
62     uint16_t DSIreqID;
63     uint8_t  AFPcommand;
64     uint32_t result;
65 } rc_elem_t;
66
67 /*
68  * AFP replay cache:
69  * - fix sized array
70  * - indexed just by taking DSIreqID mod REPLAYCACHE_SIZE
71  */
72 rc_elem_t replaycache[REPLAYCACHE_SIZE];
73
74 static void afp_dsi_close(AFPObj *obj)
75 {
76     DSI *dsi = obj->handle;
77
78     close(obj->ipc_fd);
79     obj->ipc_fd = -1;
80
81     /* we may have been called from a signal handler caught when afpd was running
82      * as uid 0, that's the wrong user for volume's prexec_close scripts if any,
83      * restore our login user
84      */
85     if (geteuid() != obj->uid) {
86         if (seteuid( obj->uid ) < 0) {
87             LOG(log_error, logtype_afpd, "can't seteuid(%u) back %s: uid: %u, euid: %u", 
88                 obj->uid, strerror(errno), getuid(), geteuid());
89             exit(EXITERR_SYS);
90         }
91     }
92
93     close_all_vol();
94     if (obj->logout)
95         (*obj->logout)();
96
97     LOG(log_info, logtype_afpd, "AFP statistics: %.2f KB read, %.2f KB written",
98         dsi->read_count/1024.0, dsi->write_count/1024.0);
99     log_dircache_stat();
100
101     dsi_close(dsi);
102 }
103
104 /* -------------------------------
105  * SIGTERM
106  * a little bit of code duplication. 
107  */
108 static void afp_dsi_die(int sig)
109 {
110 static volatile int in_handler;
111     
112     if (in_handler) {
113         return;
114     }
115     /* it's not atomic but we don't care because it's an exit function
116      * ie if a signal is received here, between the test and the affectation,
117      * it will not return.
118     */
119     in_handler = 1;
120
121     dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN);
122     afp_dsi_close(child.obj);
123     if (sig) /* if no signal, assume dieing because logins are disabled &
124                 don't log it (maintenance mode)*/
125         LOG(log_info, logtype_afpd, "Connection terminated");
126     if (sig == SIGTERM || sig == SIGALRM) {
127         exit( 0 );
128     }
129     else {
130         exit(sig);
131     }
132 }
133
134 static void afp_dsi_transfer_session(int sig _U_)
135 {
136     uint16_t dsiID;
137     int socket;
138     DSI *dsi = (DSI *)child.obj->handle;
139
140     LOG(log_note, logtype_afpd, "afp_dsi_transfer_session: got SIGURG, trying to receive session");
141
142     if (readt(child.obj->ipc_fd, &dsiID, 2, 0, 2) != 2) {
143         LOG(log_error, logtype_afpd, "afp_dsi_transfer_session: couldn't receive DSI id, goodbye");
144         afp_dsi_close(child.obj);
145         exit(EXITERR_SYS);
146     }
147
148     if ((socket = recv_fd(child.obj->ipc_fd, 1)) == -1) {
149         LOG(log_error, logtype_afpd, "afp_dsi_transfer_session: couldn't receive session fd, goodbye");
150         afp_dsi_close(child.obj);
151         exit(EXITERR_SYS);
152     }
153
154     if (dsi->socket != -1)
155         close(dsi->socket);
156     dsi->socket = socket;
157     dsi->header.dsi_requestID = dsiID;
158     dsi->header.dsi_len = 0;
159     dsi->header.dsi_code = AFP_OK;
160     dsi->header.dsi_command = DSIFUNC_CMD;
161     dsi->header.dsi_flags = DSIFL_REPLY;
162
163     /*
164      * The session transfer happens in the middle of FPDisconnect old session, thus we
165      * have to send the reply now.
166      */
167     if (!dsi_cmdreply(dsi, AFP_OK)) {
168         LOG(log_error, logtype_afpd, "dsi_cmdreply: %s", strerror(errno) );
169         afp_dsi_close(child.obj);
170         exit(EXITERR_CLNT);
171     }
172
173     LOG(log_note, logtype_afpd, "afp_dsi_transfer_session: succesfull primary reconnect");
174     /* 
175      * Now returning from this signal handler return to dsi_receive which should start
176      * reading/continuing from the connected socket that was passed via the parent from
177      * another session. The parent will terminate that session.
178      */
179 }
180
181 /* */
182 static void afp_dsi_sleep(void)
183 {
184     dsi_sleep(child.obj->handle, 1);
185 }
186
187 /* ------------------- */
188 static void afp_dsi_timedown(int sig _U_)
189 {
190     struct sigaction    sv;
191     struct itimerval    it;
192     DSI                 *dsi = (DSI *)child.obj->handle;
193     dsi->flags |= DSI_DIE;
194     /* shutdown and don't reconnect. server going down in 5 minutes. */
195     setmessage("The server is going down for maintenance.");
196     if (dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT |
197                   AFPATTN_MESG | AFPATTN_TIME(5)) < 0) {
198         DSI *dsi = (DSI *) child.obj->handle;
199         dsi->down_request = 1;
200     }                  
201
202     it.it_interval.tv_sec = 0;
203     it.it_interval.tv_usec = 0;
204     it.it_value.tv_sec = 300;
205     it.it_value.tv_usec = 0;
206
207     if ( setitimer( ITIMER_REAL, &it, NULL ) < 0 ) {
208         LOG(log_error, logtype_afpd, "afp_timedown: setitimer: %s", strerror(errno) );
209         afp_dsi_die(EXITERR_SYS);
210     }
211     memset(&sv, 0, sizeof(sv));
212     sv.sa_handler = afp_dsi_die;
213     sigemptyset( &sv.sa_mask );
214     sigaddset(&sv.sa_mask, SIGHUP);
215     sigaddset(&sv.sa_mask, SIGTERM);
216     sv.sa_flags = SA_RESTART;
217     if ( sigaction( SIGALRM, &sv, NULL ) < 0 ) {
218         LOG(log_error, logtype_afpd, "afp_timedown: sigaction: %s", strerror(errno) );
219         afp_dsi_die(EXITERR_SYS);
220     }
221
222     /* ignore myself */
223     sv.sa_handler = SIG_IGN;
224     sigemptyset( &sv.sa_mask );
225     sv.sa_flags = SA_RESTART;
226     if ( sigaction( SIGUSR1, &sv, NULL ) < 0 ) {
227         LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGHUP: %s", strerror(errno) );
228         afp_dsi_die(EXITERR_SYS);
229     }
230 }
231
232 /* ---------------------------------
233  * SIGHUP reload configuration file
234  */
235 volatile int reload_request = 0;
236
237 static void afp_dsi_reload(int sig _U_)
238 {
239     reload_request = 1;
240 }
241
242 /* ---------------------------------
243  * SIGINT: enable max_debug LOGging
244  */
245 static volatile sig_atomic_t debug_request = 0;
246
247 static void afp_dsi_debug(int sig _U_)
248 {
249     debug_request = 1;
250 }
251
252 /* ---------------------- */
253 #ifdef SERVERTEXT
254 static void afp_dsi_getmesg (int sig _U_)
255 {
256     DSI *dsi = (DSI *) child.obj->handle;
257
258     dsi->msg_request = 1;
259     if (dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5)) < 0)
260         dsi->msg_request = 2;
261 }
262 #endif /* SERVERTEXT */
263
264 static void alarm_handler(int sig _U_)
265 {
266     int err;
267     DSI *dsi = (DSI *) child.obj->handle;
268
269     /* we have to restart the timer because some libraries may use alarm() */
270     setitimer(ITIMER_REAL, &dsi->timer, NULL);
271
272     /* we got some traffic from the client since the previous timer tick. */
273     if ((dsi->flags & DSI_DATA)) {
274         dsi->flags &= ~DSI_DATA;
275         dsi->flags &= ~DSI_DISCONNECTED;
276        return;
277     }
278
279     child.tickle++;
280
281     if (dsi->flags & DSI_SLEEPING) {
282         if (child.tickle < child.obj->options.sleep) {
283             LOG(log_error, logtype_afpd, "afp_alarm: sleep time ended");
284             afp_dsi_die(EXITERR_CLNT);
285         }
286         return;
287     } 
288
289     if (dsi->flags & DSI_DISCONNECTED) {
290         if (child.tickle > child.obj->options.disconnected) {
291              LOG(log_error, logtype_afpd, "afp_alarm: no reconnect within 10 minutes, goodbye");
292             afp_dsi_die(EXITERR_CLNT);
293         }
294         return;
295     }
296
297     /* if we're in the midst of processing something, don't die. */        
298     if ( !(dsi->flags & DSI_RUNNING) && (child.tickle > child.obj->options.timeout)) {
299         LOG(log_error, logtype_afpd, "afp_alarm: child timed out, entering disconnected state");
300         dsi->flags |= DSI_DISCONNECTED;
301         return;
302     }
303
304     if ((err = pollvoltime(child.obj)) == 0)
305         err = dsi_tickle(child.obj->handle);
306     if (err <= 0) {
307         LOG(log_error, logtype_afpd, "afp_alarm: connection problem, entering disconnected state");
308         dsi->flags |= DSI_DISCONNECTED;
309     }
310 }
311
312 /* ----------------- 
313    if dsi->in_write is set attention, tickle (and close?) msg
314    aren't sent. We don't care about tickle 
315 */
316 static void pending_request(DSI *dsi)
317 {
318     /* send pending attention */
319
320     /* read msg if any, it could be done in afp_getsrvrmesg */
321     if (dsi->msg_request) {
322         if (dsi->msg_request == 2) {
323             /* didn't send it in signal handler */
324             dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5));
325         }
326         dsi->msg_request = 0;
327         readmessage(child.obj);
328     }
329     if (dsi->down_request) {
330         dsi->down_request = 0;
331         dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT |
332                   AFPATTN_MESG | AFPATTN_TIME(5));
333     }
334 }
335
336 /* -------------------------------------------
337  afp over dsi. this never returns. 
338 */
339 void afp_over_dsi(AFPObj *obj)
340 {
341     DSI *dsi = (DSI *) obj->handle;
342     int rc_idx;
343     u_int32_t err, cmd;
344     u_int8_t function;
345     struct sigaction action;
346
347     AFPobj = obj;
348     obj->exit = afp_dsi_die;
349     obj->reply = (int (*)()) dsi_cmdreply;
350     obj->attention = (int (*)(void *, AFPUserBytes)) dsi_attention;
351
352     obj->sleep = afp_dsi_sleep;
353     child.obj = obj;
354     child.tickle = child.flags = 0;
355
356     memset(&action, 0, sizeof(action));
357
358     /* install SIGHUP */
359     action.sa_handler = afp_dsi_reload;
360     sigemptyset( &action.sa_mask );
361     sigaddset(&action.sa_mask, SIGALRM);
362     sigaddset(&action.sa_mask, SIGTERM);
363     sigaddset(&action.sa_mask, SIGUSR1);
364     sigaddset(&action.sa_mask, SIGINT);
365 #ifdef SERVERTEXT
366     sigaddset(&action.sa_mask, SIGUSR2);
367 #endif    
368     action.sa_flags = SA_RESTART;
369     if ( sigaction( SIGHUP, &action, NULL ) < 0 ) {
370         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
371         afp_dsi_die(EXITERR_SYS);
372     }
373
374     /* install SIGURG */
375     action.sa_handler = afp_dsi_transfer_session;
376     sigemptyset( &action.sa_mask );
377     sigaddset(&action.sa_mask, SIGALRM);
378     sigaddset(&action.sa_mask, SIGTERM);
379     sigaddset(&action.sa_mask, SIGUSR1);
380     sigaddset(&action.sa_mask, SIGINT);
381 #ifdef SERVERTEXT
382     sigaddset(&action.sa_mask, SIGUSR2);
383 #endif    
384     action.sa_flags = SA_RESTART;
385     if ( sigaction( SIGURG, &action, NULL ) < 0 ) {
386         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
387         afp_dsi_die(EXITERR_SYS);
388     }
389
390     /* install SIGTERM */
391     action.sa_handler = afp_dsi_die;
392     sigemptyset( &action.sa_mask );
393     sigaddset(&action.sa_mask, SIGALRM);
394     sigaddset(&action.sa_mask, SIGHUP);
395     sigaddset(&action.sa_mask, SIGUSR1);
396     sigaddset(&action.sa_mask, SIGINT);
397 #ifdef SERVERTEXT
398     sigaddset(&action.sa_mask, SIGUSR2);
399 #endif    
400     action.sa_flags = SA_RESTART;
401     if ( sigaction( SIGTERM, &action, NULL ) < 0 ) {
402         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
403         afp_dsi_die(EXITERR_SYS);
404     }
405
406 #ifdef SERVERTEXT
407     /* Added for server message support */
408     action.sa_handler = afp_dsi_getmesg;
409     sigemptyset( &action.sa_mask );
410     sigaddset(&action.sa_mask, SIGALRM);
411     sigaddset(&action.sa_mask, SIGTERM);
412     sigaddset(&action.sa_mask, SIGUSR1);
413     sigaddset(&action.sa_mask, SIGHUP);
414     sigaddset(&action.sa_mask, SIGINT);
415     action.sa_flags = SA_RESTART;
416     if ( sigaction( SIGUSR2, &action, NULL) < 0 ) {
417         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
418         afp_dsi_die(EXITERR_SYS);
419     }
420 #endif /* SERVERTEXT */
421
422     /*  SIGUSR1 - set down in 5 minutes  */
423     action.sa_handler = afp_dsi_timedown;
424     sigemptyset( &action.sa_mask );
425     sigaddset(&action.sa_mask, SIGALRM);
426     sigaddset(&action.sa_mask, SIGHUP);
427     sigaddset(&action.sa_mask, SIGTERM);
428     sigaddset(&action.sa_mask, SIGINT);
429 #ifdef SERVERTEXT
430     sigaddset(&action.sa_mask, SIGUSR2);
431 #endif    
432     action.sa_flags = SA_RESTART;
433     if ( sigaction( SIGUSR1, &action, NULL) < 0 ) {
434         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
435         afp_dsi_die(EXITERR_SYS);
436     }
437
438     /*  SIGINT - enable max_debug LOGging to /tmp/afpd.PID.XXXXXX */
439     action.sa_handler = afp_dsi_debug;
440     sigfillset( &action.sa_mask );
441     action.sa_flags = SA_RESTART;
442     if ( sigaction( SIGINT, &action, NULL) < 0 ) {
443         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
444         afp_dsi_die(EXITERR_SYS);
445     }
446
447 #ifndef DEBUGGING
448     /* tickle handler */
449     action.sa_handler = alarm_handler;
450     sigemptyset(&action.sa_mask);
451     sigaddset(&action.sa_mask, SIGHUP);
452     sigaddset(&action.sa_mask, SIGTERM);
453     sigaddset(&action.sa_mask, SIGUSR1);
454     sigaddset(&action.sa_mask, SIGINT);
455 #ifdef SERVERTEXT
456     sigaddset(&action.sa_mask, SIGUSR2);
457 #endif    
458     action.sa_flags = SA_RESTART; /* dont restart, otherwi */
459     if ((sigaction(SIGALRM, &action, NULL) < 0) ||
460             (setitimer(ITIMER_REAL, &dsi->timer, NULL) < 0)) {
461         afp_dsi_die(EXITERR_SYS);
462     }
463 #endif /* DEBUGGING */
464
465     if (dircache_init(obj->options.dircachesize) != 0)
466         afp_dsi_die(EXITERR_SYS);
467
468     /* get stuck here until the end */
469     while (1) {
470         cmd = dsi_receive(dsi);
471         if (cmd == 0) {
472             /* Some error on the client connection, enter disconnected state */
473             dsi->flags |= DSI_DISCONNECTED;
474             pause(); /* gets interrupted by SIGALARM or SIGURG tickle */
475             continue; /* continue receiving until disconnect timer expires
476                        * or a primary reconnect succeeds  */
477         }
478
479         child.tickle = 0;
480         dsi_sleep(dsi, 0); /* wake up */
481
482         if (reload_request) {
483             reload_request = 0;
484             load_volumes(child.obj);
485             dircache_dump();
486             log_dircache_stat();
487         }
488
489         /* The first SIGINT enables debugging, the next restores the config */
490         if (debug_request) {
491             static int debugging = 0;
492             debug_request = 0;
493
494             if (debugging) {
495                 if (obj->options.logconfig)
496                     setuplog(obj->options.logconfig);
497                 else
498                     setuplog("default log_note");
499                 debugging = 0;
500             } else {
501                 char logstr[50];
502                 debugging = 1;
503                 sprintf(logstr, "default log_maxdebug /tmp/afpd.%u.XXXXXX", getpid());
504                 setuplog(logstr);
505             }
506         }
507
508         if (cmd == DSIFUNC_TICKLE) {
509             /* timer is not every 30 seconds anymore, so we don't get killed on the client side. */
510             if ((dsi->flags & DSI_DIE))
511                 dsi_tickle(dsi);
512             pending_request(dsi);
513             continue;
514         } 
515
516         dsi->flags |= DSI_DATA;
517         switch(cmd) {
518         case DSIFUNC_CLOSE:
519             afp_dsi_close(obj);
520             LOG(log_info, logtype_afpd, "done");
521             return;
522             break;
523
524         case DSIFUNC_CMD:
525 #ifdef AFS
526             if ( writtenfork ) {
527                 if ( flushfork( writtenfork ) < 0 ) {
528                     LOG(log_error, logtype_afpd, "main flushfork: %s", strerror(errno) );
529                 }
530                 writtenfork = NULL;
531             }
532 #endif /* AFS */
533
534             function = (u_char) dsi->commands[0];
535
536             /* AFP replay cache */
537             rc_idx = REPLAYCACHE_SIZE % dsi->clientID;
538             LOG(log_debug, logtype_afpd, "DSI request ID: %u", dsi->clientID);
539
540             if (replaycache[rc_idx].DSIreqID == dsi->clientID
541                 && replaycache[rc_idx].AFPcommand == function) {
542                 LOG(log_debug, logtype_afpd, "AFP Replay Cache match: id: %u / cmd: %s",
543                     dsi->clientID, AfpNum2name(function));
544                 err = replaycache[rc_idx].result;
545             /* AFP replay cache end */
546             } else {
547                 /* send off an afp command. in a couple cases, we take advantage
548                  * of the fact that we're a stream-based protocol. */
549                 if (afp_switch[function]) {
550                     dsi->datalen = DSI_DATASIZ;
551                     dsi->flags |= DSI_RUNNING;
552
553                     LOG(log_debug, logtype_afpd, "<== Start AFP command: %s", AfpNum2name(function));
554
555                     err = (*afp_switch[function])(obj,
556                                                   (char *)&dsi->commands, dsi->cmdlen,
557                                                   (char *)&dsi->data, &dsi->datalen);
558
559                     LOG(log_debug, logtype_afpd, "==> Finished AFP command: %s -> %s",
560                         AfpNum2name(function), AfpErr2name(err));
561
562                     dir_free_invalid_q();
563
564 #ifdef FORCE_UIDGID
565                     /* bring everything back to old euid, egid */
566                     if (obj->force_uid)
567                         restore_uidgid ( &obj->uidgid );
568 #endif /* FORCE_UIDGID */
569                     dsi->flags &= ~DSI_RUNNING;
570
571                     /* Add result to the AFP replay cache */
572                     replaycache[rc_idx].DSIreqID = dsi->clientID;
573                     replaycache[rc_idx].AFPcommand = function;
574                     replaycache[rc_idx].result = err;
575                 } else {
576                     LOG(log_error, logtype_afpd, "bad function %X", function);
577                     dsi->datalen = 0;
578                     err = AFPERR_NOOP;
579                 }
580             }
581
582             /* single shot toggle that gets set by dsi_readinit. */
583             if (dsi->noreply) {
584                 dsi->noreply = 0;
585                 break;
586             }
587
588             if (!dsi_cmdreply(dsi, err)) {
589                 LOG(log_error, logtype_afpd, "dsi_cmdreply(%d): %s", dsi->socket, strerror(errno) );
590                 afp_dsi_die(EXITERR_CLNT);
591             }
592             break;
593
594         case DSIFUNC_WRITE: /* FPWrite and FPAddIcon */
595             function = (u_char) dsi->commands[0];
596             if ( afp_switch[ function ] != NULL ) {
597                 dsi->datalen = DSI_DATASIZ;
598                 dsi->flags |= DSI_RUNNING;
599
600                 LOG(log_debug, logtype_afpd, "<== Start AFP command: %s", AfpNum2name(function));
601
602                 err = (*afp_switch[function])(obj,
603                                               (char *)&dsi->commands, dsi->cmdlen,
604                                               (char *)&dsi->data, &dsi->datalen);
605
606                 LOG(log_debug, logtype_afpd, "==> Finished AFP command: %s -> %s",
607                     AfpNum2name(function), AfpErr2name(err));
608
609                 dsi->flags &= ~DSI_RUNNING;
610 #ifdef FORCE_UIDGID
611                 /* bring everything back to old euid, egid */
612                 if (obj->force_uid)
613                     restore_uidgid ( &obj->uidgid );
614 #endif /* FORCE_UIDGID */
615             } else {
616                 LOG(log_error, logtype_afpd, "(write) bad function %x", function);
617                 dsi->datalen = 0;
618                 err = AFPERR_NOOP;
619             }
620
621             if (!dsi_wrtreply(dsi, err)) {
622                 LOG(log_error, logtype_afpd, "dsi_wrtreply: %s", strerror(errno) );
623                 afp_dsi_die(EXITERR_CLNT);
624             }
625             break;
626
627         case DSIFUNC_ATTN: /* attention replies */
628             break;
629
630             /* error. this usually implies a mismatch of some kind
631              * between server and client. if things are correct,
632              * we need to flush the rest of the packet if necessary. */
633         default:
634             LOG(log_info, logtype_afpd,"afp_dsi: spurious command %d", cmd);
635             dsi_writeinit(dsi, dsi->data, DSI_DATASIZ);
636             dsi_writeflush(dsi);
637             break;
638         }
639         pending_request(dsi);
640     }
641
642     /* error */
643     afp_dsi_die(EXITERR_CLNT);
644 }