1
1

* utilvfs.h (vfs_parse_filetype, vfs_parse_fileperms,

vfs_parse_filemode): Rewrote the functions to parse Unix file
	modes.
	* utilvfs.c: Likewise.
	* fish.c: Using the new parsing functions.
Этот коммит содержится в:
Roland Illig 2005-09-26 11:10:24 +00:00
родитель aac7ac441a
Коммит 290b842c86
4 изменённых файлов: 142 добавлений и 150 удалений

Просмотреть файл

@ -1,3 +1,11 @@
2005-09-26 Roland Illig <roland.illig@gmx.de>
* utilvfs.h (vfs_parse_filetype, vfs_parse_fileperms,
vfs_parse_filemode): Rewrote the functions to parse Unix file
modes.
* utilvfs.c: Likewise.
* fish.c: Using the new parsing functions.
2005-09-15 Andrew V. Samoilov <sav@bcs.zp.ua> 2005-09-15 Andrew V. Samoilov <sav@bcs.zp.ua>
* samba/lib/util.c (tab_depth): Remove. * samba/lib/util.c (tab_depth): Remove.

Просмотреть файл

@ -440,17 +440,14 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
#endif #endif
break; break;
case 'P': { case 'P': {
int i; size_t skipped;
if ((i = vfs_parse_filetype(buffer[1])) ==-1)
break; if (vfs_parse_filemode (buffer + 1, &skipped, &ST.st_mode)) {
ST.st_mode = i; if (S_ISLNK(ST.st_mode))
if ((i = vfs_parse_filemode(buffer+2)) ==-1) ST.st_mode = 0;
break; }
ST.st_mode |= i; break;
if (S_ISLNK(ST.st_mode)) }
ST.st_mode = 0;
}
break;
case 'd': { case 'd': {
vfs_split_text(buffer+1); vfs_split_text(buffer+1);
if (!vfs_parse_filedate(0, &ST.st_ctime)) if (!vfs_parse_filedate(0, &ST.st_ctime))

Просмотреть файл

@ -413,151 +413,134 @@ is_year (char *str, struct tm *tim)
* where "2904 1234" is filename. Well, this code decodes it as year :-(. * where "2904 1234" is filename. Well, this code decodes it as year :-(.
*/ */
int gboolean
vfs_parse_filetype (char c) vfs_parse_filetype (const char *s, size_t *ret_skipped, mode_t *ret_type)
{ {
switch (c) { mode_t type;
case 'd':
return S_IFDIR; switch (*s) {
case 'b': case 'd': type = S_IFDIR; break;
return S_IFBLK; case 'b': type = S_IFBLK; break;
case 'c': case 'c': type = S_IFCHR; break;
return S_IFCHR; case 'l': type = S_IFLNK; break;
case 'l':
return S_IFLNK;
case 's': /* Socket */
#ifdef S_IFSOCK #ifdef S_IFSOCK
return S_IFSOCK; case 's': type = S_IFSOCK; break;
#else #else
/* If not supported, we fall through to IFIFO */ case 's': type = S_IFIFO; break;
return S_IFIFO;
#endif #endif
case 'D': /* Solaris door */ #ifdef S_IFDOOR /* Solaris door */
#ifdef S_IFDOOR case 'D': type = S_IFDOOR; break;
return S_IFDOOR;
#else #else
return S_IFIFO; case 'D': type = S_IFIFO; break;
#endif #endif
case 'p': case 'p': type = S_IFIFO; break;
return S_IFIFO; #ifdef S_IFNAM /* Special named files */
case 'n': /* Special named files */ case 'n': type = S_IFNAM; break;
#ifdef S_IFNAM #else
return S_IFNAM; case 'n': type = S_IFREG; break;
#endif /* S_IFNAM */ #endif
case 'm': /* Don't know what these are :-) */ case 'm': /* Don't know what these are :-) */
case '-': case '-':
case '?': case '?': type = S_IFREG; break;
return S_IFREG; default: return FALSE;
default:
return -1;
} }
*ret_type = type;
*ret_skipped = 1;
return TRUE;
} }
int gboolean
vfs_parse_filemode (const char *p) vfs_parse_fileperms (const char *s, size_t *ret_skipped, mode_t *ret_perms)
{ /* converts rw-rw-rw- into 0666 */ {
int res = 0; const char *p;
switch (*(p++)) { mode_t perms;
case 'r':
res |= 0400; p = s;
break; perms = 0;
case '-':
break; switch (*p++) {
default: case '-': break;
return -1; case 'r': perms |= S_IRUSR; break;
default: return FALSE;
} }
switch (*(p++)) { switch (*p++) {
case 'w': case '-': break;
res |= 0200; case 'w': perms |= S_IWUSR; break;
break; default: return FALSE;
case '-':
break;
default:
return -1;
} }
switch (*(p++)) { switch (*p++) {
case 'x': case '-': break;
res |= 0100; case 'S': perms |= S_ISUID; break;
break; case 's': perms |= S_IXUSR | S_ISUID; break;
case 's': case 'x': perms |= S_IXUSR; break;
res |= 0100 | S_ISUID; default: return FALSE;
break;
case 'S':
res |= S_ISUID;
break;
case '-':
break;
default:
return -1;
} }
switch (*(p++)) { switch (*p++) {
case 'r': case '-': break;
res |= 0040; case 'r': perms |= S_IRGRP; break;
break; default: return FALSE;
case '-':
break;
default:
return -1;
} }
switch (*(p++)) { switch (*p++) {
case 'w': case '-': break;
res |= 0020; case 'w': perms |= S_IWGRP; break;
break; default: return FALSE;
case '-':
break;
default:
return -1;
} }
switch (*(p++)) { switch (*p++) {
case 'x': case '-': break;
res |= 0010; case 'S': perms |= S_ISGID; break;
break; case 'l': perms |= S_ISGID; break; /* found on Solaris */
case 's': case 's': perms |= S_IXGRP | S_ISGID; break;
res |= 0010 | S_ISGID; case 'x': perms |= S_IXGRP; break;
break; default: return FALSE;
case 'l': /* Solaris produces these */
case 'S':
res |= S_ISGID;
break;
case '-':
break;
default:
return -1;
} }
switch (*(p++)) { switch (*p++) {
case 'r': case '-': break;
res |= 0004; case 'r': perms |= S_IROTH; break;
break; default: return FALSE;
case '-':
break;
default:
return -1;
} }
switch (*(p++)) { switch (*p++) {
case 'w': case '-': break;
res |= 0002; case 'w': perms |= S_IWOTH; break;
break; default: return FALSE;
case '-':
break;
default:
return -1;
} }
switch (*(p++)) { switch (*p++) {
case 'x': case '-': break;
res |= 0001; case 'T': perms |= S_ISVTX; break;
break; case 't': perms |= S_IXOTH | S_ISVTX; break;
case 't': case 'x': perms |= S_IXOTH; break;
res |= 0001 | S_ISVTX; default: return FALSE;
break;
case 'T':
res |= S_ISVTX;
break;
case '-':
break;
default:
return -1;
} }
return res; if (*p == '+') { /* ACLs on Solaris, HP-UX and others */
p++;
}
*ret_skipped = p - s;
*ret_perms = perms;
return TRUE;
}
gboolean
vfs_parse_filemode (const char *s, size_t *ret_skipped,
mode_t *ret_mode)
{
const char *p;
mode_t type, perms;
size_t skipped;
p = s;
if (!vfs_parse_filetype (p, &skipped, &type))
return FALSE;
p += skipped;
if (!vfs_parse_fileperms (p, &skipped, &perms))
return FALSE;
p += skipped;
*ret_skipped = p - s;
*ret_mode = type | perms;
return TRUE;
} }
/* This function parses from idx in the columns[] array */ /* This function parses from idx in the columns[] array */
@ -689,14 +672,15 @@ vfs_parse_ls_lga (const char *p, struct stat *s, char **filename,
char *p_copy = NULL; char *p_copy = NULL;
char *t = NULL; char *t = NULL;
const char *line = p; const char *line = p;
size_t skipped;
if (strncmp (p, "total", 5) == 0) if (strncmp (p, "total", 5) == 0)
return 0; return 0;
if ((i = vfs_parse_filetype (*(p++))) == -1) if (!vfs_parse_filetype (p, &skipped, &s->st_mode))
goto error; goto error;
p += skipped;
s->st_mode = i;
if (*p == ' ') /* Notwell 4 */ if (*p == ' ') /* Notwell 4 */
p++; p++;
if (*p == '[') { if (*p == '[') {
@ -711,14 +695,13 @@ vfs_parse_ls_lga (const char *p, struct stat *s, char **filename,
s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR); s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
p += 9; p += 9;
} else { } else {
if ((i = vfs_parse_filemode (p)) == -1) size_t skipped;
goto error; mode_t perms;
s->st_mode |= i;
p += 9;
/* This is for an extra ACL attribute (HP-UX) */ if (!vfs_parse_fileperms (p, &skipped, &perms))
if (*p == '+') goto error;
p++; p += skipped;
s->st_mode |= perms;
} }
p_copy = g_strdup (p); p_copy = g_strdup (p);
@ -878,4 +861,3 @@ vfs_get_password (const char *msg)
{ {
return input_dialog (msg, _("Password:"), INPUT_PASSWORD); return input_dialog (msg, _("Password:"), INPUT_PASSWORD);
} }

Просмотреть файл

@ -18,10 +18,15 @@ int vfs_mkstemps (char **pname, const char *prefix, const char *basename);
void vfs_die (const char *msg); void vfs_die (const char *msg);
char *vfs_get_password (const char *msg); char *vfs_get_password (const char *msg);
gboolean vfs_parse_filetype (const char *s, size_t *ret_skipped,
mode_t *ret_type);
gboolean vfs_parse_fileperms (const char *s, size_t *ret_skipped,
mode_t *ret_perms);
gboolean vfs_parse_filemode (const char *s, size_t *ret_skipped,
mode_t *ret_mode);
int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename,
char **linkname); char **linkname);
int vfs_parse_filetype (char c);
int vfs_parse_filemode (const char *p);
int vfs_parse_filedate (int idx, time_t *t); int vfs_parse_filedate (int idx, time_t *t);
#endif #endif