/*
- * $Id: messages.c,v 1.16.6.1 2003-06-23 10:25:08 didg Exp $
+ * $Id: messages.c,v 1.16.6.1.2.1 2003-09-09 16:42:20 didg Exp $
*
* Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <stdlib.h>
#include <atalk/afp.h>
+#include <atalk/dsi.h>
#include <atalk/logger.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
+#include <atalk/unicode.h>
#include "globals.h"
#include "misc.h"
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif /* ! MAX */
+
#define MAXMESGSIZE 199
/* this is only used by afpd children, so it's okay. */
-static char servermesg[MAXMESGSIZE] = "";
+static char servermesg[MAXPATHLEN] = "";
+static char localized_message[MAXPATHLEN] = "";
void setmessage(const char *message)
{
strncpy(servermesg, message, MAXMESGSIZE);
}
-void readmessage(void)
+void readmessage(obj)
+AFPObj *obj;
{
/* Read server message from file defined as SERVERTEXT */
#ifdef SERVERTEXT
FILE *message;
char * filename;
- int i, rc;
+ unsigned int i;
+ int rc;
static int c;
uid_t euid;
+ u_int32_t maxmsgsize;
+
+ maxmsgsize = (obj->proto == AFPPROTO_DSI)?MIN(MAX(((DSI*)obj->handle)->attn_quantum, MAXMESGSIZE),MAXPATHLEN):MAXMESGSIZE;
i=0;
/* Construct file name SERVERTEXT/message.[pid] */
/* if either message.pid or message exists */
if (message!=NULL) {
/* added while loop to get characters and put in servermesg */
- while ((( c=fgetc(message)) != EOF) && (i < (MAXMESGSIZE - 1))) {
+ while ((( c=fgetc(message)) != EOF) && (i < (maxmsgsize - 1))) {
if ( c == '\n') c = ' ';
servermesg[i++] = c;
}
strerror(errno));
}
- rc = unlink(filename);
+ if ( 0 < (rc = unlink(filename)) )
+ LOG(log_error, logtype_afpd, "File '%s' could not be deleted", strerror(errno));
/* Drop privs again, failing this is very bad */
if (seteuid(euid) < 0) {
{
char *message;
u_int16_t type, bitmap;
+ u_int32_t msgsize;
+ size_t outlen;
+
+ msgsize = (obj->proto == AFPPROTO_DSI)?MAX(((DSI*)obj->handle)->attn_quantum, MAXMESGSIZE):MAXMESGSIZE;
memcpy(&type, ibuf + 2, sizeof(type));
memcpy(&bitmap, ibuf + 4, sizeof(bitmap));
memcpy(rbuf, &bitmap, sizeof(bitmap));
rbuf += sizeof(bitmap);
*rbuflen = strlen(message);
+#if 0
if (*rbuflen > MAXMESGSIZE)
*rbuflen = MAXMESGSIZE;
+#endif
+ if (*rbuflen > msgsize)
+ *rbuflen = msgsize;
*rbuf++ = *rbuflen;
- memcpy(rbuf, message, *rbuflen);
+
+ /* Convert the message to the macs codepage
+ * according to AFP 3.1 specs page 200
+ * bit 1 set in bitmap means Unicode ?= utf8
+ * Never saw this in the wild yet */
+
+ if ( (size_t)-1 == (outlen = convert_charset(obj->options.unixcharset, ((ntohs(bitmap)) & 2)?CH_UTF8_MAC:obj->options.maccharset, message, *rbuflen, localized_message, msgsize, 0)) )
+ memcpy(rbuf, message, *rbuflen); /*FIXME*/
+ else
+ memcpy(rbuf, localized_message, outlen);
*rbuflen += 5;