-/*
- Taken form afpd/desktop.c
-*/
-static char *mtoupath(char *mpath)
-{
- static char upath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */
- char *m, *u;
- size_t inplen;
- size_t outlen;
- u_int16_t flags = 0;
-
- if (!mpath)
- return NULL;
-
- if ( *mpath == '\0' ) {
- return( "." );
- }
-
- /* set conversion flags */
- if (!(myvolinfo->v_flags & AFPVOL_NOHEX))
- flags |= CONV_ESCAPEHEX;
- if (!(myvolinfo->v_flags & AFPVOL_USEDOTS))
- flags |= CONV_ESCAPEDOTS;
-
- if ((myvolinfo->v_casefold & AFPVOL_MTOUUPPER))
- flags |= CONV_TOUPPER;
- else if ((myvolinfo->v_casefold & AFPVOL_MTOULOWER))
- flags |= CONV_TOLOWER;
-
- if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) {
- flags |= CONV__EILSEQ;
- }
-
- m = mpath;
- u = upath;
-
- inplen = strlen(m);
- outlen = MAXPATHLEN;
-
- if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC,
- myvolinfo->v_volcharset,
- myvolinfo->v_maccharset,
- m, inplen, u, outlen, &flags)) ) {
- dbd_log( LOGSTD, "conversion from UTF8-MAC to %s for %s failed.",
- myvolinfo->v_volcodepage, mpath);
- return NULL;
- }
-
- return( upath );
-}
-
-#if 0
-/*
- Check if "name" is pointing to
- a) an object inside the current volume (return 0)
- b) an object outside the current volume (return 1)
- Then stats the pointed to object and if it is a dir ors ADFLAGS_DIR to *adflags
- Return -1 on any serious error.
- */
-static int check_symlink(const char *name, int *adflags)
-{
- int cwd;
- ssize_t len;
- char pathbuf[MAXPATHLEN + 1];
- char *sep;
- struct stat st;
-
- if ((len = readlink(name, pathbuf, MAXPATHLEN)) == -1) {
- dbd_log(LOGSTD, "Error reading link info for '%s/%s': %s",
- cwdbuf, name, strerror(errno));
- return -1;
- }
- pathbuf[len] = 0;
-
- if ((stat(pathbuf, &st)) != 0) {
- dbd_log(LOGSTD, "stat error '%s': %s", pathbuf, strerror(errno));
- }
-
- /* Remember cwd */
- if ((cwd = open(".", O_RDONLY)) < 0) {
- dbd_log(LOGSTD, "error opening cwd '%s': %s", cwdbuf, strerror(errno));
- return -1;
- }
-
- if (S_ISDIR(st.st_mode)) {
- *adflags |= ADFLAGS_DIR;
- } else { /* file */
- /* get basename from path */
- if ((sep = strrchr(pathbuf, '/')) == NULL)
- /* just a file at the same level */
- return 0;
- sep = 0; /* pathbuf now contains the directory*/
- }
-
- /* fchdir() to pathbuf so we can easily get its path with getcwd() */
- if ((chdir(pathbuf)) != 0) {
- dbd_log(LOGSTD, "Cant chdir to '%s': %s", pathbuf, strerror(errno));
- return -1;
- }
-
- if ((getcwd(pathbuf, MAXPATHLEN)) == NULL) {
- dbd_log(LOGSTD, "Cant get symlink'ed dir '%s/%s': %s", cwdbuf, pathbuf, strerror(errno));
- if ((fchdir(cwd)) != 0)
- /* We're foobared */
- longjmp(jmp, 1); /* this jumps back to cmd_dbd_scanvol() */
- return -1;
- }
-
- if ((fchdir(cwd)) != 0)
- /* We're foobared */
- longjmp(jmp, 1); /* this jumps back to cmd_dbd_scanvol() */
-
- /*
- We now have the symlink target dir as absoulte path in pathbuf
- and can compare it with the currents volume path
- */
- int i = 0;
- while (myvolinfo->v_path[i]) {
- if ((pathbuf[i] == 0) || (myvolinfo->v_path[i] != pathbuf[i])) {
- dbd_log( LOGDEBUG, "extra-share symlink '%s/%s', following", cwdbuf, name);
- return 1;
- }
- i++;
- }
-
- dbd_log( LOGDEBUG, "intra-share symlink '%s/%s', not following", cwdbuf, name);
- return 0;
-}
-#endif
-
-/*
- Check for wrong encoding e.g. "." at the beginning is not CAP encoded (:2e) although volume is default !AFPVOL_USEDOTS.
- We do it by roundtripiping from volcharset to UTF8-MAC and back and then compare the result.
-*/
-static int check_name_encoding(char *uname)
-{
- char *roundtripped;
-
- roundtripped = mtoupath(utompath(uname));
- if (!roundtripped) {
- dbd_log( LOGSTD, "Error checking encoding for '%s/%s'", cwdbuf, uname);
- return -1;
- }
-
- if ( STRCMP(uname, !=, roundtripped)) {
- dbd_log( LOGSTD, "Bad encoding for '%s/%s'", cwdbuf, uname);
- return -1;
- }
-
- return 0;
-}
-