2 * $Id: unix.c,v 1.1 2009-10-02 09:32:41 franklahm Exp $
4 * Copyright (c) 1990,1993 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
11 #endif /* HAVE_CONFIG_H */
15 #include <sys/param.h>
16 #include <sys/types.h>
20 #include <atalk/afp.h>
21 #include <atalk/util.h>
22 #include <atalk/directory.h>
23 #include <atalk/volume.h>
24 #include <atalk/logger.h>
26 /* -----------------------------
27 a dropbox is a folder where w is set but not r eg:
29 rwx----wx (is not asked by a Mac with OS >= 8.0 ?)
31 int stickydirmode(const char *name, const mode_t mode, const int dropbox, const mode_t v_umask)
36 /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */
37 if ((dropbox & AFPVOL_DROPBOX)) {
40 if ( ( (mode & S_IWOTH) && !(mode & S_IROTH)) ||
41 ( (mode & S_IWGRP) && !(mode & S_IRGRP)) )
44 if ( seteuid(0) < 0) {
45 LOG(log_error, logtype_afpd, "stickydirmode: unable to seteuid root: %s", strerror(errno));
47 if ( (retval=chmod( name, ( (DIRBITS | mode | S_ISVTX) & ~v_umask) )) < 0) {
48 LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(errno) );
50 LOG(log_debug, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(retval) );
56 #endif /* DROPKLUDGE */
59 * Ignore EPERM errors: We may be dealing with a directory that is
60 * group writable, in which case chmod will fail.
62 if ( (chmod( name, (DIRBITS | mode) & ~v_umask ) < 0) && errno != EPERM &&
63 !(errno == ENOENT && (dropbox & AFPVOL_NOADOUBLE)) )
65 LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(errno) );
72 /* ------------------------- */
73 int dir_rx_set(mode_t mode)
75 return (mode & (S_IXUSR | S_IRUSR)) == (S_IXUSR | S_IRUSR);
78 /* --------------------- */
79 int setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
82 mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO; /* rwx for owner group and other, by default */
85 if (stat(name, &sb) != 0)
90 mode |= st->st_mode & ~mask; /* keep other bits from previous mode */
91 if ( chmod( name, mode & ~v_umask ) < 0 && errno != EPERM ) {
97 /* -------------------
98 system rmdir with afp error code.
99 ENOENT is not an error.
101 int netatalk_rmdir(const char *name)
103 if (rmdir(name) < 0) {
108 return AFPERR_DIRNEMPT;
111 return AFPERR_ACCESS;
121 /* -------------------
122 system unlink with afp error code.
123 ENOENT is not an error.
125 int netatalk_unlink(const char *name)
127 if (unlink(name) < 0) {
135 return AFPERR_ACCESS;
143 char *fullpathname(const char *name)
145 static char wd[ MAXPATHLEN + 1];
147 if ( getcwd( wd , MAXPATHLEN) ) {
148 strlcat(wd, "/", MAXPATHLEN);
149 strlcat(wd, name, MAXPATHLEN);
152 strlcpy(wd, name, MAXPATHLEN);