-/*
+/*
* Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#endif /* HAVE_CONFIG_H */
#include <sys/types.h>
-#include <sys/acl.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <string.h>
#include <libgen.h>
+#ifdef HAVE_SOLARIS_ACLS
+#include <sys/acl.h>
+#endif /* HAVE_SOLARIS_ACLS */
+
+#ifdef HAVE_POSIX_ACLS
+#include <sys/types.h>
+#include <sys/acl.h>
+#endif /* HAVE_POSIX_ACLS */
+
#include <atalk/util.h>
#include <atalk/cnid.h>
#include <atalk/volinfo.h>
/*!
* Load volinfo and initialize struct vol
*
- * Only opens "dbd" volumes !
+ * Only opens "dbd" volumes !
*
* @param path (r) path to evaluate
- * @param vol (rw) structure to initialize
+ * @param vol (rw) structure to initialize
*
* @returns 0 on success, exits on error
*/
memset(vol, 0, sizeof(afpvol_t));
/* try to find a .AppleDesktop/.volinfo */
- if (loadvolinfo((char *)path, &vol->volinfo) == 0) {
+ if (loadvolinfo((char *)path, &vol->volinfo) != 0)
+ return -1;
- if (STRCMP(vol->volinfo.v_cnidscheme, != , "dbd"))
- ERROR("\"%s\" isn't a \"dbd\" CNID volume!", vol->volinfo.v_path);
+ if (STRCMP(vol->volinfo.v_cnidscheme, != , "dbd"))
+ ERROR("\"%s\" isn't a \"dbd\" CNID volume!", vol->volinfo.v_path);
- if (vol_load_charsets(&vol->volinfo) == -1)
- ERROR("Error loading charsets!");
+ if (vol_load_charsets(&vol->volinfo) == -1)
+ ERROR("Error loading charsets!");
- /* Sanity checks to ensure we can touch this volume */
- if (vol->volinfo.v_adouble != AD_VERSION2)
- ERROR("Unsupported adouble versions: %u", vol->volinfo.v_adouble);
+ /* Sanity checks to ensure we can touch this volume */
+ if (vol->volinfo.v_adouble != AD_VERSION2)
+ ERROR("Unsupported adouble versions: %u", vol->volinfo.v_adouble);
- if (vol->volinfo.v_vfs_ea != AFPVOL_EA_SYS)
- ERROR("Unsupported Extended Attributes option: %u", vol->volinfo.v_vfs_ea);
+ if (vol->volinfo.v_vfs_ea != AFPVOL_EA_SYS)
+ ERROR("Unsupported Extended Attributes option: %u", vol->volinfo.v_vfs_ea);
- /* initialize sufficient struct vol for VFS initialisation */
- vol->volume.v_adouble = AD_VERSION2;
- vol->volume.v_vfs_ea = AFPVOL_EA_SYS;
- initvol_vfs(&vol->volume);
+ /* initialize sufficient struct vol for VFS initialisation */
+ vol->volume.v_adouble = AD_VERSION2;
+ vol->volume.v_vfs_ea = AFPVOL_EA_SYS;
+ initvol_vfs(&vol->volume);
- if ((vol->volinfo.v_flags & AFPVOL_NODEV))
- flags |= CNID_FLAG_NODEV;
+ if ((vol->volinfo.v_flags & AFPVOL_NODEV))
+ flags |= CNID_FLAG_NODEV;
- if ((vol->volume.v_cdb = cnid_open(vol->volinfo.v_dbpath,
- 0000,
- "dbd",
- flags,
- vol->volinfo.v_dbd_host,
- vol->volinfo.v_dbd_port)) == NULL)
- ERROR("Cant initialize CNID database connection for %s", vol->volinfo.v_path);
-
- cnid_getstamp(vol->volume.v_cdb,
- vol->db_stamp,
- sizeof(vol->db_stamp));
- }
+ if ((vol->volume.v_cdb = cnid_open(vol->volinfo.v_path,
+ 0000,
+ "dbd",
+ flags,
+ vol->volinfo.v_dbd_host,
+ vol->volinfo.v_dbd_port)) == NULL)
+ ERROR("Cant initialize CNID database connection for %s", vol->volinfo.v_path);
+ cnid_getstamp(vol->volume.v_cdb,
+ vol->db_stamp,
+ sizeof(vol->db_stamp));
+
return 0;
}
volinfo->v_maccharset,
u, outlen, mpath, MAXPATHLEN, &flags)) ) {
SLOG("Conversion from %s to %s for %s failed.",
- volinfo->v_volcodepage, volinfo->v_maccodepage, u);
+ volinfo->v_volcodepage, volinfo->v_maccodepage, u);
return NULL;
}
* "/afp_volume/dir/subdir"
*
* @param path (r) path relative to cwd() or absolute
- * @param volpath (r) volume path that path is a subdir of (has been computed in volinfo funcs)
+ * @param volpath (r) volume path that path is a subdir of (has been computed in volinfo funcs)
*
* @returns relative path in new bstring, caller must bdestroy it
*/
EC_NEG1_LOG(cwd = open(".", O_RDONLY));
- EC_ZERO_LOGSTR(stat(path, &st), "stat(%s): %s", path, strerror(errno));
+ EC_ZERO_LOGSTR(lstat(path, &st), "lstat(%s): %s", path, strerror(errno));
switch (S_IFMT & st.st_mode) {
case S_IFREG:
+ case S_IFLNK:
EC_NULL_LOG(dname = strdup(path));
EC_ZERO_LOGSTR(chdir(dirname(dname)), "chdir(%s): %s", dirname, strerror(errno));
free(dname);
EC_CLEANUP:
if (dname) free(dname);
- if (cwd != -1)
+ if (cwd != -1) {
fchdir(cwd);
+ close(cwd);
+ }
if (ret != 0)
return NULL;
return fpath;
for (int i = 0; i < l->qty ; i++) {
*did = cnid;
EC_ZERO(bconcat(statpath, l->entry[i]));
- EC_ZERO_LOGSTR(stat(cfrombstr(statpath), &st),
- "stat(rpath: %s, elem: %s): %s: %s",
+ EC_ZERO_LOGSTR(lstat(cfrombstr(statpath), &st),
+ "lstat(rpath: %s, elem: %s): %s: %s",
cfrombstr(rpath), cfrombstr(l->entry[i]),
cfrombstr(statpath), strerror(errno));
if ((cnid = cnid_add(vol->volume.v_cdb,
- &st,
- *did,
- cfrombstr(l->entry[i]),
- blength(l->entry[i]),
+ &st,
+ *did,
+ cfrombstr(l->entry[i]),
+ blength(l->entry[i]),
0)) == CNID_INVALID) {
EC_FAIL;
}
- EC_ZERO(bcatcstr(statpath, "/"));
+ EC_ZERO(bcatcstr(statpath, "/"));
}
EC_CLEANUP:
l = bsplit(rpath, '/');
if (l->qty == 1)
/* only one path element, means parent dir cnid is volume root = 2 */
- EC_EXIT;
+ goto EC_CLEANUP;
for (int i = 0; i < (l->qty - 1); i++) {
*did = cnid;
EC_ZERO(bconcat(statpath, l->entry[i]));
- EC_ZERO_LOGSTR(stat(cfrombstr(statpath), &st),
- "stat(rpath: %s, elem: %s): %s: %s",
+ EC_ZERO_LOGSTR(lstat(cfrombstr(statpath), &st),
+ "lstat(rpath: %s, elem: %s): %s: %s",
cfrombstr(rpath), cfrombstr(l->entry[i]),
cfrombstr(statpath), strerror(errno));
if ((cnid = cnid_add(vol->volume.v_cdb,
- &st,
- *did,
- cfrombstr(l->entry[i]),
- blength(l->entry[i]),
+ &st,
+ *did,
+ cfrombstr(l->entry[i]),
+ blength(l->entry[i]),
0)) == CNID_INVALID) {
EC_FAIL;
}
- EC_ZERO(bcatcstr(statpath, "/"));
+ EC_ZERO(bcatcstr(statpath, "/"));
}
EC_CLEANUP: