X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=etc%2Fafpd%2Fmessages.c;h=3c85f6a3a505c7fe9ae4c5ade65a5c44f997e708;hp=241f0d08166a166ed2a4b22f8d8b5e088c0b7876;hb=4111aba41c36a99bfd7eb7e987b24314735cdd10;hpb=e00467826a7ea8dd706d0728191b13894d25618d diff --git a/etc/afpd/messages.c b/etc/afpd/messages.c index 241f0d08..3c85f6a3 100644 --- a/etc/afpd/messages.c +++ b/etc/afpd/messages.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -40,7 +41,6 @@ void readmessage(AFPObj *obj) unsigned int i; int rc; static int c; - uid_t euid; uint32_t maxmsgsize; maxmsgsize = MIN(MAX(obj->dsi->attn_quantum, MAXMESGSIZE), MAXPATHLEN); @@ -77,22 +77,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));