]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/messages.c
implemented config.h
[netatalk.git] / etc / afpd / messages.c
1 /* 
2  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <atalk/afp.h>
13 #include "globals.h"
14 #include "misc.h"
15
16 #define MAXMESGSIZE 199
17
18 /* this is only used by afpd children, so it's okay. */
19 static char servermesg[MAXMESGSIZE] = "";
20
21 void setmessage(const char *message)
22 {
23   strncpy(servermesg, message, MAXMESGSIZE);
24 }
25
26 int afp_getsrvrmesg(obj, ibuf, ibuflen, rbuf, rbuflen)
27      AFPObj *obj;
28      char *ibuf, *rbuf;
29      int ibuflen, *rbuflen;
30 {
31   char *message;
32   u_int16_t type, bitmap;
33
34   memcpy(&type, ibuf + 2, sizeof(type));
35   memcpy(&bitmap, ibuf + 4, sizeof(bitmap));
36
37   switch (ntohs(type)) {
38   case AFPMESG_LOGIN: /* login */
39     message = obj->options.loginmesg;
40     break;
41   case AFPMESG_SERVER: /* server */
42     message = servermesg;
43     break;
44   default:
45     *rbuflen = 0;
46     return AFPERR_BITMAP;
47   }
48
49   /* output format:
50    * message type:   2 bytes
51    * bitmap:         2 bytes
52    * message length: 1 byte
53    * message:        up to 199 bytes
54    */
55   memcpy(rbuf, &type, sizeof(type));
56   rbuf += sizeof(type);
57   memcpy(rbuf, &bitmap, sizeof(bitmap));
58   rbuf += sizeof(bitmap);
59   *rbuflen = strlen(message);
60   if (*rbuflen > MAXMESGSIZE)
61     *rbuflen = MAXMESGSIZE;
62   *rbuf++ = *rbuflen;
63   memcpy(rbuf, message, *rbuflen);
64
65   *rbuflen += 5;
66
67   return AFP_OK;
68 }