/*
- $Id: ea.c,v 1.7 2009-10-20 08:38:41 franklahm Exp $
+ $Id: ea.c,v 1.8 2009-10-21 17:41:45 franklahm Exp $
Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
This program is free software; you can redistribute it and/or modify
return mode;
}
+/*
+ Taken form afpd/desktop.c
+*/
+static char *mtoupath(const struct vol *vol, const char *mpath)
+{
+ static char upath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */
+ const char *m;
+ char *u;
+ size_t inplen;
+ size_t outlen;
+ uint16_t flags = CONV_ESCAPEHEX;
+
+ if (!mpath)
+ return NULL;
+
+ if ( *mpath == '\0' ) {
+ return( "." );
+ }
+
+ m = mpath;
+ u = upath;
+
+ inplen = strlen(m);
+ outlen = MAXPATHLEN;
+
+ if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC,
+ vol->v_volcharset,
+ vol->v_maccharset,
+ m, inplen, u, outlen, &flags)) ) {
+ return NULL;
+ }
+
+ return( upath );
+}
+
+
/*
* Function: unpack_header
*
* ea (r) ea handle
* eaname (r) name of EA or NULL
*
- * Returns: pointer to name in static buffer
+ * Returns: pointer to name in static buffer, NULL on error
*
* Effects:
*
if (eaname) {
strlcat(pathbuf, "::", MAXPATHLEN + 1);
+ if ((eaname = mtoupath(ea->vol, eaname)) == NULL)
+ return NULL;
strlcat(pathbuf, eaname, MAXPATHLEN + 1);
}
struct stat st;
char *eaname;
- eaname = ea_path(ea, attruname);
- LOG(log_maxdebug, logtype_afpd, "write_ea: ea_apth: %s", eaname);
+ if ((eaname = ea_path(ea, attruname)) == NULL) {
+ LOG(log_error, logtype_afpd, "write_ea('%s'): ea_path error", attruname);
+ return AFPERR_MISC;
+ }
+
+ LOG(log_maxdebug, logtype_afpd, "write_ea('%s')", eaname);
/* Check if it exists, remove if yes*/
if ((stat(eaname, &st)) == 0) {
}
if ((write(fd, ibuf, attrsize)) != attrsize) {
- LOG(log_error, logtype_afpd, "write_ea: short write: %s", eaname);
+ LOG(log_error, logtype_afpd, "write_ea('%s'): write: %s", eaname, strerror(errno));
ret = -1;
goto exit;
}
char *eafile;
struct stat st;
- eafile = ea_path(ea, eaname);
+ if ((eafile = ea_path(ea, eaname)) == NULL) {
+ LOG(log_error, logtype_afpd, "delete_ea_file('%s'): ea_path error", eaname);
+ return -1;
+ }
/* Check if it exists, remove if yes*/
if ((stat(eafile, &st)) == 0) {
uint32_t uint32;
size_t toread;
struct ea ea;
+ char *eafile;
LOG(log_debug, logtype_afpd, "get_eacontent('%s/%s')", uname, attruname);
while (count < ea.ea_count) {
if (strcmp(attruname, (*ea.ea_entries)[count].ea_name) == 0) {
- if ((fd = open(ea_path(&ea, attruname), O_RDONLY)) == -1) {
+ if ( (eafile = ea_path(&ea, attruname)) == NULL) {
+ ret = AFPERR_MISC;
+ break;
+ }
+
+ if ((fd = open(eafile, O_RDONLY)) == -1) {
ret = AFPERR_MISC;
break;
}
easize = (*srcea.ea_entries)[count].ea_size;
/* Build src and dst paths for rename() */
- eapath = ea_path(&srcea, eaname);
+ if ((eapath = ea_path(&srcea, eaname)) == NULL) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
strcpy(srceapath, eapath);
- eapath = ea_path(&dstea, eaname);
+ if ((eapath = ea_path(&dstea, eaname)) == NULL) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
LOG(log_maxdebug, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
src, dst, srceapath, eapath);
easize = (*srcea.ea_entries)[count].ea_size;
/* Build src and dst paths for copy_file() */
- eapath = ea_path(&srcea, eaname);
+ if ((eapath = ea_path(&srcea, eaname)) == NULL) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
strcpy(srceapath, eapath);
- eapath = ea_path(&dstea, eaname);
+ if ((eapath = ea_path(&dstea, eaname)) == NULL) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
LOG(log_maxdebug, logtype_afpd, "ea_copyfile('%s/%s'): copying EA '%s' to '%s'",
src, dst, srceapath, eapath);
}
while (count < ea.ea_count) {
- eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name);
+ if ((eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name)) == NULL) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
if ((chown(eaname, uid, gid)) != 0) {
switch (errno) {
case EPERM:
/* Set mode on EA files */
while (count < ea.ea_count) {
- eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name);
+ if ((eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name)) == NULL) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
if ((setfilmode(eaname, ea_mode(mode), NULL, vol->v_umask)) != 0) {
LOG(log_error, logtype_afpd, "ea_chmod_file('%s'): %s", eaname, strerror(errno));
switch (errno) {
LOG(log_warning, logtype_afpd, "ea_chmod_dir('%s'): contains a slash", eaname);
eaname = eaname_safe;
}
- eaname = ea_path(&ea, eaname);
+ if ((eaname = ea_path(&ea, eaname)) == NULL) {
+ ret = AFPERR_MISC;
+ goto exit;
+ }
if ((setfilmode(eaname, ea_mode(mode), NULL, vol->v_umask)) != 0) {
LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): %s", eaname, strerror(errno));
switch (errno) {