3 #ifdef HAVE_SYS_TYPES_H
6 #ifdef HAVE_SYS_SOCKET_H
7 #include <sys/socket.h>
13 # define dirent direct
14 # define NAMLEN(dirent) (dirent)->d_namlen
15 # ifdef HAVE_SYS_NDIR_H
16 # include <sys/ndir.h>
18 # ifdef HAVE_SYS_DIR_H
27 #ifdef HAVE_SYS_STAT_H
34 #ifdef HAVE_SYS_TIME_H
51 struct hidegroup *hidegroups = NULL;
53 void add_to_hidegroups(int gid)
55 static struct hidegroup *tmp = NULL;
57 tmp = tmp->next = malloc(sizeof(struct hidegroup));
59 hidegroups = tmp = malloc(sizeof(struct hidegroup));
64 void hidegroups_init()
66 char *foo = strdup(config_getoption("HIDE_GROUP"));
70 while ((bar = strtok(foo, ","))) {
71 foo = NULL; /* strtok requirement */
72 if ((strcmp(bar, "0")) && (!strtoul(bar, NULL, 10))) {
73 /* bar is not numeric */
74 if ((tmpgrp = getgrnam(bar)))
75 add_to_hidegroups(tmpgrp->gr_gid);
77 if (strtoul(bar, NULL, 10))
78 add_to_hidegroups(strtoul(bar, NULL, 10));
85 struct hidegroup *tmp = hidegroups;
87 while (hidegroups->next) {
88 tmp = hidegroups->next;
94 void bftpd_stat(char *name, FILE * client)
97 char temp[MAXCMD + 3], linktarget[MAXCMD + 5], perm[11], timestr[17],
98 uid[USERLEN + 1], gid[USERLEN + 1];
101 if (lstat(name, (struct stat *) &statbuf) == -1) { // used for command_stat
102 fprintf(client, "213-Error: %s.\n", strerror(errno));
106 if (S_ISLNK(statbuf.st_mode)) {
107 strcpy(perm, "lrwxrwxrwx");
108 temp[readlink(name, temp, sizeof(temp) - 1)] = '\0';
109 sprintf(linktarget, " -> %s", temp);
112 strcpy(perm, "----------");
113 if (S_ISDIR(statbuf.st_mode))
115 if (statbuf.st_mode & S_IRUSR)
117 if (statbuf.st_mode & S_IWUSR)
119 if (statbuf.st_mode & S_IXUSR)
121 if (statbuf.st_mode & S_IRGRP)
123 if (statbuf.st_mode & S_IWGRP)
125 if (statbuf.st_mode & S_IXGRP)
127 if (statbuf.st_mode & S_IROTH)
129 if (statbuf.st_mode & S_IWOTH)
131 if (statbuf.st_mode & S_IXOTH)
133 linktarget[0] = '\0';
137 memcpy(&filetime, localtime(&(statbuf.st_mtime)), sizeof(struct tm));
139 if (filetime.tm_year == localtime(&t)->tm_year)
140 mystrncpy(timestr, ctime(&(statbuf.st_mtime)) + 4, 12);
142 strftime(timestr, sizeof(timestr), "%b %d %G", &filetime);
143 mygetpwuid(statbuf.st_uid, passwdfile, uid)[8] = 0;
144 mygetpwuid(statbuf.st_gid, groupfile, gid)[8] = 0;
145 fprintf(client, "%s %3i %-8s %-8s %8lu %s %s%s\r\n", perm,
146 (int) statbuf.st_nlink, uid, gid,
147 (unsigned long) statbuf.st_size,
148 timestr, name, linktarget);
151 void dirlist_one_file(char *name, FILE *client, char verbose)
154 struct hidegroup *tmp = hidegroups;
155 if (!stat(name, (struct stat *) &statbuf)) {
158 if (statbuf.st_gid == tmp->data)
160 } while ((tmp = tmp->next));
163 bftpd_stat(name, client);
165 fprintf(client, "%s\r\n", name);
168 void dirlist(char *name, FILE * client, char verbose)
174 if ((strstr(name, "/.")) && strchr(name, '*'))
175 return; /* DoS protection */
176 if ((directory = opendir(name))) {
178 cwd = bftpd_cwd_getcwd();
180 glob("*", 0, NULL, &globbuf);
182 glob(name, 0, NULL, &globbuf);
183 for (i = 0; i < globbuf.gl_pathc; i++)
184 dirlist_one_file(globbuf.gl_pathv[i], client, verbose);