Example #1
0
static TACommandVerdict __lxstat_cmd(TAThread thread,TAInputStream stream)
{
    struct stat buffer;
    int res;
    char* path;

    // Prepare
    path = readString(&stream);

    START_TARGET_OPERATION(thread);
    errno=0;
#if (__i386__ || __powerpc__ || (__s390__ && !__s390x__))  
    res = __lxstat(3, path, &buffer);
#else        
    res = __lxstat(0, path, &buffer);
#endif
    VERBOSE("after lstat atime==%d\n", buffer.st_atime);
    END_TARGET_OPERATION(thread);

    // Response
    writeInt(thread, res);
    writeInt(thread, errno);
    writeFileStatus(thread, &buffer);

    sendResponse(thread);

    return taDefaultVerdict;
}
Example #2
0
/* Get file information about FILE in BUF.  */
int
__lxstat64 (int vers, const char *file, struct stat64 *buf)
{
  struct stat st;
  int ret = __lxstat(vers,file,&st);
  __convert_stat64(&st,buf);
  return ret;
}
Example #3
0
int lstat(char *name, void *st)
{
#if HAVE___LXSTAT
    return __lxstat(0, name, st);
#else
    if (smbw_path(name)) {
        return smbw_stat(name, st);
    }
    return real_lstat(name, st);
#endif
}
Example #4
0
int
attribute_hidden
__lstat (const char *file, struct stat *buf)
{
  return __lxstat (_STAT_VER, file, buf);
}
Example #5
0
static char *canonicalize (const char *name)
{
	char *rpath, *dest, *extra_buf = NULL;
	const char *start, *end, *rpath_limit;
	long int path_max;
	int num_links = 0, err = 0;

	if (name == NULL) {
		/* As per Single Unix Specification V2 we must return an error if
			 either parameter is a null pointer.	We extend this to allow
			 the RESOLVED parameter be NULL in case the we are expected to
			 allocate the room for the return value.	*/
		__set_errno (EINVAL);
		return NULL;
	}

	if (name[0] == '\0') {
		/* As per Single Unix Specification V2 we must return an error if
			 the name argument points to an empty string.	*/
		__set_errno (ENOENT);
		return NULL;
	}

#ifdef PATH_MAX
	path_max = PATH_MAX;
#else
	path_max = pathconf (name, _PC_PATH_MAX);
	if (path_max <= 0)
		path_max = 1024;
#endif

	rpath = (char *) __alloca (path_max);
	rpath_limit = rpath + path_max;

	if (name[0] != '/') {
		if (!__getcwd (rpath, path_max))
			goto error;
		dest = strchr (rpath, '\0');
	}
	else {
		rpath[0] = '/';
		dest = rpath + 1;
	}

	for (start = end = name; *start; start = end) {
		struct stat st;
		int n;

		/* Skip sequence of multiple path-separators.	*/
		while (*start == '/')
			++start;

		/* Find end of path component.	*/
		for (end = start; *end && *end != '/'; ++end)
			/* Nothing.	*/;

		if (end - start == 0)
			break;
		else if (end - start == 1 && start[0] == '.')
			/* nothing */;
		else if (end - start == 2 && start[0] == '.' && start[1] == '.') {
			/* Back up to previous component, ignore if at root already.	*/
			if (dest > rpath + 1)
				while ((--dest)[-1] != '/');
		}
		else {
			if (dest[-1] != '/')
				*dest++ = '/';

			if (dest + (end - start) >= rpath_limit) {
				__set_errno (ENAMETOOLONG);
				goto error;
			}

			memmove(dest, start, end - start);
			dest = (char *) dest + (end - start);
			*dest = '\0';

			/* let's try changing the semantic to always ignore
			 * underlying filesystem if path so far is in capfstab file.
			 * That way we don't get silly kernel errors when using the
			 * library.  This is easy - just move (well, just copy for
			 * now) the search_fstab check to here. If you get a match,
			 * increment err.  err doesn't actually signal a fatal error,
			 * just causes it to quit getting at underlying
			 * filesystem. -- don
			 *
			 */

			if (search_fstab(rpath)) { /* rpath is in the capfstab */
				err++;
			}
			
			/* we used to crap out in this case; now we simply note that we
			 * hit an error and stop trying to stat from now on. -- Rob
			 */

			if (!err && __lxstat (_STAT_VER, rpath, &st) < 0) {
				err++;
			}
			if (!err && (S_ISLNK (st.st_mode))) {
				char *buf = (char *) __alloca (path_max);
				size_t len;

				if (++num_links > MAXSYMLINKS) {
					__set_errno (ELOOP);
					goto error;
				}

				n = __readlink (rpath, buf, path_max);
				if (n < 0)
					goto error;
				buf[n] = '\0';

				if (!extra_buf)
					extra_buf = (char *) __alloca (path_max);

				len = strlen (end);
				if ((long int) (n + len) >= path_max) {
					__set_errno (ENAMETOOLONG);
					goto error;
				}

				/* Careful here, end may be a pointer into extra_buf... */
				memmove (&extra_buf[n], end, len + 1);
				name = end = memcpy (extra_buf, buf, n);

				if (buf[0] == '/')
					dest = rpath + 1;	/* It's an absolute symlink */
				else
					/* Back up to previous component, ignore if at root already: */
					if (dest > rpath + 1)
						while ((--dest)[-1] != '/');
			}
		}
	}
	if (dest > rpath + 1 && dest[-1] == '/')
		--dest;
	*dest = '\0';

	memcpy(canonicalize_outbuf, rpath, dest - rpath + 1);
	return(canonicalize_outbuf);

error:
	/* copy in component causing trouble */
	strcpy (canonicalize_outbuf, rpath);
	return(canonicalize_outbuf);
}
Example #6
0
/* 3 of 3: _lxstat */
int
_lxstat (int vers, const char *name, struct stat *buf)
{
    return __lxstat (vers, name, buf);
}
Example #7
0
__attribute__((weak)) int lstat(const char *path, struct stat *buf) { return __lxstat(1, path, buf); }
Example #8
0
int __xstat(int ver, const char *path, struct stat *buf)
{
	return __lxstat(ver, path, buf);
}