3 * Copyright (C) 2002 Florin Malita <mali@go.ro>
5 * This file is part of LUFS, a free userspace filesystem implementation.
6 * See http://lufs.sourceforge.net/ for updates.
8 * LUFS is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * LUFS is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <sys/types.h>
39 #include <lufs/proto.h>
43 #include "ftpsys_unix.h"
47 while( (*c != ' ') && (*c != 0))
58 nth_word(char *line, int n){
62 for(c = line, i = 0; (c != NULL) && (i < n); i++)
68 ftpsys_unix::ftpsys_unix(){
69 CMD_LIST = "LIST -al";
72 ftpsys_unix::~ftpsys_unix(){
77 ftpsys_unix::parse_line(char *buf, char *file, struct lufs_fattr *fattr, char *link, struct credentials *cred){
78 unsigned long nlink, size;
82 char user[32], group[32], month[5], day[5], year[6], date[20];
85 *file = *link = user[0] = group[0] = month[0] = day[0] = year[0] = 0;
87 if((res = sscanf(buf, "%*11s %lu %32s %32s %lu %3s %2s %5s %1024s -> %1024s", &nlink, user, group, &size, month, day, year, file, link)) < 7){
88 TRACE("could only match "<<res<<" attributes");
92 sprintf(date,"%s,%s,%s", year, month, day);
95 tm.tm_sec = tm.tm_min = tm.tm_hour = 0;
97 strptime(date, "%H:%M,%b,%d", &tm);
99 strptime(date, "%Y,%b,%d", &tm);
101 memset(fattr, 0, sizeof(struct lufs_fattr));
103 strtol(user, &c, 10);
105 if((int)cred->uid == atoi(user))
108 if(!strcmp(cred->user, user))
112 strtol(group, &c, 10);
114 if((int)cred->gid == atoi(group))
117 if(!strcmp(cred->group, group))
121 fattr->f_nlink = nlink;
122 fattr->f_size = size;
123 fattr->f_ctime = fattr->f_mtime = fattr->f_atime = mktime(&tm);
125 if(tolower(buf[0]) == 'd') fattr->f_mode = S_IFDIR;
126 else if(tolower(buf[0]) == 'l') fattr->f_mode = S_IFLNK;
127 else fattr->f_mode = S_IFREG;
129 if(tolower(buf[1]) != '-') fattr->f_mode |= S_IRUSR;
130 if(tolower(buf[2]) != '-') fattr->f_mode |= S_IWUSR;
131 if(tolower(buf[3]) != '-') fattr->f_mode |= S_IXUSR;
132 if(tolower(buf[4]) != '-') fattr->f_mode |= S_IRGRP;
133 if(tolower(buf[5]) != '-') fattr->f_mode |= S_IWGRP;
134 if(tolower(buf[6]) != '-') fattr->f_mode |= S_IXGRP;
135 if(tolower(buf[7]) != '-') fattr->f_mode |= S_IROTH;
136 if(tolower(buf[8]) != '-') fattr->f_mode |= S_IWOTH;
137 if(tolower(buf[9]) != '-') fattr->f_mode |= S_IXOTH;
139 for(c = buf; *c; c++){
140 if((*c == 0x0a) || (*c == 0x0d)){
147 if((c = nth_word(buf, 8))){
149 TRACE("left: " << c);
154 strcpy(link, (cc + 3));
159 TRACE("file: " << file<<", link: " << link);