/*
- * $Id: messages.c,v 1.22 2009-10-29 13:38:15 didg Exp $
- *
* Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
*/
#include "config.h"
#endif /* HAVE_CONFIG_H */
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <atalk/dsi.h>
#include <atalk/util.h>
#include <atalk/logger.h>
-#include "globals.h"
+#include <atalk/globals.h>
+
#include "misc.h"
int rc;
static int c;
uid_t euid;
- u_int32_t maxmsgsize;
+ uint32_t maxmsgsize;
- maxmsgsize = (obj->proto == AFPPROTO_DSI)?MIN(MAX(((DSI*)obj->handle)->attn_quantum, MAXMESGSIZE),MAXPATHLEN):MAXMESGSIZE;
+ maxmsgsize = (obj->proto == AFPPROTO_DSI)?MIN(MAX(((DSI*)obj->dsi)->attn_quantum, MAXMESGSIZE),MAXPATHLEN):MAXMESGSIZE;
i=0;
/* Construct file name SERVERTEXT/message.[pid] */
message=fopen(filename, "r");
if (message==NULL) {
- LOG(log_info, logtype_afpd, "Unable to open file %s", filename);
+ /* try without the process id */
sprintf(filename, "%s/message", SERVERTEXT);
message=fopen(filename, "r");
}
strerror(errno));
}
- if ( 0 < (rc = unlink(filename)) )
+ if ((rc = unlink(filename)) != 0)
LOG(log_error, logtype_afpd, "File '%s' could not be deleted", strerror(errno));
/* Drop privs again, failing this is very bad */
int afp_getsrvrmesg(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
{
char *message;
- u_int16_t type, bitmap;
- u_int16_t msgsize;
+ uint16_t type, bitmap;
+ uint16_t msgsize;
size_t outlen = 0;
size_t msglen = 0;
int utf8 = 0;
*rbuflen = 0;
- msgsize = (obj->proto == AFPPROTO_DSI)?MAX(((DSI*)obj->handle)->attn_quantum, MAXMESGSIZE):MAXMESGSIZE;
+ msgsize = (obj->proto == AFPPROTO_DSI)?MAX(((DSI*)obj->dsi)->attn_quantum, MAXMESGSIZE):MAXMESGSIZE;
memcpy(&type, ibuf + 2, sizeof(type));
memcpy(&bitmap, ibuf + 4, sizeof(bitmap));
+ message = servermesg;
switch (ntohs(type)) {
case AFPMESG_LOGIN: /* login */
- message = obj->options.loginmesg;
+ /* at least TIGER loses server messages
+ * if it receives a server msg attention before
+ * it has asked the login msg...
+ * Workaround: concatenate the two if any, ugly.
+ */
+ if (*message && *obj->options.loginmesg) {
+ strlcat(message, " - ", MAXMESGSIZE);
+ }
+ strlcat(message, obj->options.loginmesg, MAXMESGSIZE);
break;
case AFPMESG_SERVER: /* server */
- message = servermesg;
break;
default:
return AFPERR_BITMAP;
*rbuflen += 1;
}
*rbuflen += outlen;
-
+ *message = 0;
return AFP_OK;
}