/*
- * $Id: volume.c,v 1.101 2009-11-09 01:36:18 didg Exp $
+ * $Id: volume.c,v 1.106 2009-11-24 15:44:40 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
} else if (optionok(tmp, "ea:", val)) {
if (strcasecmp(val + 1, "ad") == 0) /* the default anyway */
options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_AD;
- else if (strcasecmp(val + 1, "solaris") == 0)
- options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_SOLARIS;
+ else if (strcasecmp(val + 1, "sys") == 0)
+ options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_SYS;
} else {
/* ignore unknown options */
if (tmpvlen + suffixlen > obj->options.volnamelen) {
flags = CONV_FORCE;
tmpvlen = convert_charset(obj->options.unixcharset, CH_UTF8_MAC, 0, name, vlen, tmpname, obj->options.volnamelen - suffixlen, &flags);
- tmpname[tmpvlen != (size_t)-1 ? tmpvlen : 0] = 0;
+ tmpname[tmpvlen >= 0 ? tmpvlen : 0] = 0;
}
strcat(tmpname, suffix);
tmpvlen = strlen(tmpname);
if (tmpvlen + suffixlen > AFPVOL_MACNAMELEN) {
flags = CONV_FORCE;
tmpvlen = convert_charset(obj->options.unixcharset, obj->options.maccharset, 0, name, vlen, tmpname, AFPVOL_MACNAMELEN - suffixlen, &flags);
- tmpname[tmpvlen != (size_t)-1 ? tmpvlen : 0] = 0;
+ tmpname[tmpvlen >= 0 ? tmpvlen : 0] = 0;
}
strcat(tmpname, suffix);
tmpvlen = strlen(tmpname);
return( AFP_OK );
}
+/* ------------------------- */
+static int volume_codepage(AFPObj *obj, struct vol *volume)
+{
+ struct charset_functions *charset;
+ /* Codepages */
+
+ if (!volume->v_volcodepage)
+ volume->v_volcodepage = strdup("UTF8");
+
+ if ( (charset_t) -1 == ( volume->v_volcharset = add_charset(volume->v_volcodepage)) ) {
+ LOG (log_error, logtype_afpd, "Setting codepage %s as volume codepage failed", volume->v_volcodepage);
+ return -1;
+ }
+
+ if ( NULL == (charset = find_charset_functions(volume->v_volcodepage)) || charset->flags & CHARSET_ICONV ) {
+ LOG (log_warning, logtype_afpd, "WARNING: volume encoding %s is *not* supported by netatalk, expect problems !!!!", volume->v_volcodepage);
+ }
+
+ if (!volume->v_maccodepage)
+ volume->v_maccodepage = strdup(obj->options.maccodepage);
+
+ if ( (charset_t) -1 == ( volume->v_maccharset = add_charset(volume->v_maccodepage)) ) {
+ LOG (log_error, logtype_afpd, "Setting codepage %s as mac codepage failed", volume->v_maccodepage);
+ return -1;
+ }
+
+ if ( NULL == ( charset = find_charset_functions(volume->v_maccodepage)) || ! (charset->flags & CHARSET_CLIENT) ) {
+ LOG (log_error, logtype_afpd, "Fatal error: mac charset %s not supported", volume->v_maccodepage);
+ return -1;
+ }
+ volume->v_kTextEncoding = htonl(charset->kTextEncoding);
+ return 0;
+}
+
+/* ------------------------- */
+static int volume_openDB(struct vol *volume)
+{
+ int flags = 0;
+
+ if ((volume->v_flags & AFPVOL_NODEV)) {
+ flags |= CNID_FLAG_NODEV;
+ }
+
+ if (volume->v_cnidscheme == NULL) {
+ volume->v_cnidscheme = strdup(DEFAULT_CNID_SCHEME);
+ LOG(log_info, logtype_afpd, "Volume %s use CNID scheme %s.", volume->v_path, volume->v_cnidscheme);
+ }
+ if (volume->v_dbpath)
+ volume->v_cdb = cnid_open (volume->v_dbpath, volume->v_umask, volume->v_cnidscheme, flags);
+ else
+ volume->v_cdb = cnid_open (volume->v_path, volume->v_umask, volume->v_cnidscheme, flags);
+
+ if (!volume->v_cdb) {
+ flags |= CNID_FLAG_MEMORY;
+ LOG(log_error, logtype_afpd, "Reopen volume %s using in memory temporary CNID DB.", volume->v_path);
+ volume->v_cdb = cnid_open (volume->v_path, volume->v_umask, "tdb", flags);
+#ifdef SERVERTEXT
+ /* kill ourself with SIGUSR2 aka msg pending */
+ if (volume->v_cdb) {
+ setmessage("Something wrong with the volume's DB ... FIXME with a better msg");
+ kill(getpid(), SIGUSR2);
+ /* XXX desactivate cachecnid ? */
+ }
+#endif
+ }
+
+ return (!volume->v_cdb)?-1:0;
+}
+
/* -------------------------
* we are the user here
*/
struct stat st;
char *volname;
char *p;
+
struct vol *volume;
struct dir *dir;
int len, ret;
char *vol_uname;
char *vol_mname;
char *volname_tmp;
- struct charset_functions *charset;
ibuf += 2;
memcpy(&bitmap, ibuf, sizeof( bitmap ));
bitmap = ntohs( bitmap );
ibuf += sizeof( bitmap );
+
+ *rbuflen = 0;
if (( bitmap & (1<<VOLPBIT_VID)) == 0 ) {
- *rbuflen = 0;
return AFPERR_BITMAP;
}
namelen = convert_string(obj->options.maccharset, CH_UCS2, ibuf, len, volname, sizeof(obj->oldtmp));
}
- if ( namelen <= 0){
- *rbuflen = 0;
+ if ( namelen <= 0) {
return AFPERR_PARAM;
}
}
if ( volume == NULL ) {
- *rbuflen = 0;
return AFPERR_PARAM;
}
/* check for a volume password */
if (volume->v_password && strncmp(ibuf, volume->v_password, VOLPASSLEN)) {
- *rbuflen = 0;
return AFPERR_ACCESS;
}
return stat_vol(bitmap, volume, rbuf, rbuflen);
}
- /* initialize volume variables
- * FIXME file size
- */
- if (utf8_encoding()) {
- volume->max_filename = 255;
- }
- else {
- volume->max_filename = MACFILELEN;
- }
-
- volume->v_dir = volume->v_root = NULL;
- volume->v_hash = NULL;
-
- volume->v_flags |= AFPVOL_OPEN;
- volume->v_cdb = NULL;
-
if (volume->v_root_preexec) {
if ((ret = afprun(1, volume->v_root_preexec, NULL)) && volume->v_root_preexec_close) {
LOG(log_error, logtype_afpd, "afp_openvol(%s): root preexec : %d", volume->v_path, ret );
- ret = AFPERR_MISC;
- goto openvol_err;
+ return AFPERR_MISC;
}
}
if (volume->v_preexec) {
if ((ret = afprun(0, volume->v_preexec, NULL)) && volume->v_preexec_close) {
LOG(log_error, logtype_afpd, "afp_openvol(%s): preexec : %d", volume->v_path, ret );
- ret = AFPERR_MISC;
- goto openvol_err;
+ return AFPERR_MISC;
}
}
if ( stat( volume->v_path, &st ) < 0 ) {
- ret = AFPERR_PARAM;
- goto openvol_err;
+ return AFPERR_PARAM;
}
if ( chdir( volume->v_path ) < 0 ) {
- ret = AFPERR_PARAM;
- goto openvol_err;
+ return AFPERR_PARAM;
+ }
+
+ if ( NULL == getcwd(path, MAXPATHLEN)) {
+ /* shouldn't be fatal but it will fail later */
+ LOG(log_error, logtype_afpd, "afp_openvol(%s): volume pathlen too long", volume->v_path);
+ return AFPERR_MISC;
+ }
+
+ if (volume_codepage(obj, volume) < 0) {
+ ret = AFPERR_MISC;
+ goto openvol_err;
+ }
+
+ /* initialize volume variables
+ * FIXME file size
+ */
+ if (utf8_encoding()) {
+ volume->max_filename = 255;
}
+ else {
+ volume->max_filename = MACFILELEN;
+ }
+
+ volume->v_dir = volume->v_root = NULL;
+ volume->v_hash = NULL;
+
+ volume->v_flags |= AFPVOL_OPEN;
+ volume->v_cdb = NULL;
if (utf8_encoding()) {
len = convert_string_allocate(CH_UCS2, CH_UTF8_MAC, volume->v_u8mname, namelen, &vol_mname);
goto openvol_err;
}
- if ( NULL == getcwd(path, MAXPATHLEN)) {
- /* shouldn't be fatal but it will fail later */
- LOG(log_error, logtype_afpd, "afp_openvol(%s): volume pathlen too long", volume->v_path);
- ret = AFPERR_MISC;
- goto openvol_err;
- }
-
if ((vol_uname = strrchr(path, '/')) == NULL)
vol_uname = path;
else if (*(vol_uname + 1) != '\0')
dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
dir->d_m_name_ucs2 = strdup_w(volume->v_name);
volume->v_dir = volume->v_root = dir;
+ volume->v_curdir = NULL;
volume->v_hash = dirhash();
curdir = volume->v_dir;
- if (volume->v_cnidscheme == NULL) {
- volume->v_cnidscheme = strdup(DEFAULT_CNID_SCHEME);
- LOG(log_info, logtype_afpd, "Volume %s use CNID scheme %s.", volume->v_path, volume->v_cnidscheme);
- }
- if (volume->v_dbpath)
- volume->v_cdb = cnid_open (volume->v_dbpath, volume->v_umask, volume->v_cnidscheme, (volume->v_flags & AFPVOL_NODEV));
- else
- volume->v_cdb = cnid_open (volume->v_path, volume->v_umask, volume->v_cnidscheme, (volume->v_flags & AFPVOL_NODEV));
- if (volume->v_cdb == NULL) {
+ if (volume_openDB(volume) < 0) {
LOG(log_error, logtype_afpd, "Fatal error: cannot open CNID or invalid CNID backend for %s: %s",
volume->v_path, volume->v_cnidscheme);
ret = AFPERR_MISC;
goto openvol_err;
}
- /* Codepages */
-
- if (!volume->v_volcodepage)
- volume->v_volcodepage = strdup("UTF8");
-
- if ( (charset_t) -1 == ( volume->v_volcharset = add_charset(volume->v_volcodepage)) ) {
- LOG (log_error, logtype_afpd, "Setting codepage %s as volume codepage failed", volume->v_volcodepage);
- ret = AFPERR_MISC;
- goto openvol_err;
- }
-
- if ( NULL == (charset = find_charset_functions(volume->v_volcodepage)) || charset->flags & CHARSET_ICONV ) {
- LOG (log_warning, logtype_afpd, "WARNING: volume encoding %s is *not* supported by netatalk, expect problems !!!!", volume->v_volcodepage);
- }
-
- if (!volume->v_maccodepage)
- volume->v_maccodepage = strdup(obj->options.maccodepage);
-
- if ( (charset_t) -1 == ( volume->v_maccharset = add_charset(volume->v_maccodepage)) ) {
- LOG (log_error, logtype_afpd, "Setting codepage %s as mac codepage failed", volume->v_maccodepage);
- ret = AFPERR_MISC;
- goto openvol_err;
- }
-
- if ( NULL == ( charset = find_charset_functions(volume->v_maccodepage)) || ! (charset->flags & CHARSET_CLIENT) ) {
- LOG (log_error, logtype_afpd, "Fatal error: mac charset %s not supported", volume->v_maccodepage);
- ret = AFPERR_MISC;
- goto openvol_err;
- }
- volume->v_kTextEncoding = htonl(charset->kTextEncoding);
-
ret = stat_vol(bitmap, volume, rbuf, rbuflen);
if (ret == AFP_OK) {