]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/messages.c
Spotlight: use async Tracker SPARQL API
[netatalk.git] / etc / afpd / messages.c
index 975ec7a975fda8156ad4738e87152c006c80d2a4..5bd965bd2a55fd569942f550173b80a44e27c1a5 100644 (file)
 #include <atalk/afp.h>
 #include <atalk/dsi.h>
 #include <atalk/util.h>
+#include <atalk/unix.h>
 #include <atalk/logger.h>
-#include "globals.h"
-#include "misc.h"
+#include <atalk/globals.h>
 
+#include "misc.h"
 
 #define MAXMESGSIZE 199
 
 static char servermesg[MAXPATHLEN] = "";
 static char localized_message[MAXPATHLEN] = "";
 
-void setmessage(const char *message)
+/*!
+ * Copy AFP message to message buffer
+ * @param message (r) message to send
+ * @returns 0 if this message is being set the first time, return 1 if the preceeding
+ *          message was the same
+ */
+int setmessage(const char *message)
 {
+    if (strncmp(message, servermesg, MAXMESGSIZE) == 0)
+        return 1;
     strlcpy(servermesg, message, MAXMESGSIZE);
+    return 0;
 }
 
 void readmessage(AFPObj *obj)
@@ -40,10 +50,9 @@ void readmessage(AFPObj *obj)
     unsigned int i; 
     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 = MIN(MAX(obj->dsi->attn_quantum, MAXMESGSIZE), MAXPATHLEN);
 
     i=0;
     /* Construct file name SERVERTEXT/message.[pid] */
@@ -77,22 +86,12 @@ void readmessage(AFPObj *obj)
         /* cleanup */
         fclose(message);
 
-        /* Save effective uid and switch to root to delete file. */
-        /* Delete will probably fail otherwise, but let's try anyways */
-        euid = geteuid();
-        if (seteuid(0) < 0) {
-            LOG(log_error, logtype_afpd, "Could not switch back to root: %s",
-                               strerror(errno));
-        }
+        become_root();
 
         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 */
-        if (seteuid(euid) < 0) {
-            LOG(log_error, logtype_afpd, "Could not switch back to uid %d: %s", euid, strerror(errno));
-            exit(EXITERR_SYS);
-        }
+        unbecome_root();
 
         if (rc < 0) {
             LOG(log_error, logtype_afpd, "Error deleting %s: %s", filename, strerror(rc));
@@ -112,15 +111,15 @@ void readmessage(AFPObj *obj)
 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 = MAX(obj->dsi->attn_quantum, MAXMESGSIZE);
 
     memcpy(&type, ibuf + 2, sizeof(type));
     memcpy(&bitmap, ibuf + 4, sizeof(bitmap));
@@ -133,10 +132,11 @@ int afp_getsrvrmesg(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, siz
          * it has asked the login msg...
          * Workaround: concatenate the two if any, ugly.
          */
-        if (*message && *obj->options.loginmesg) {
-            strlcat(message, " - ", MAXMESGSIZE);
+        if (obj->options.loginmesg) {
+            if (*message)
+                strlcat(message, " - ", MAXMESGSIZE);
+            strlcat(message, obj->options.loginmesg, MAXMESGSIZE);
         }
-        strlcat(message, obj->options.loginmesg, MAXMESGSIZE);
         break;
     case AFPMESG_SERVER: /* server */
         break;
@@ -186,6 +186,6 @@ int afp_getsrvrmesg(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, siz
        *rbuflen += 1;
     }
     *rbuflen += outlen;
-    *message = 0;
+//    *message = 0;
     return AFP_OK;
 }