void bftpd_stat(char *name, FILE * client) { struct stat statbuf; char temp[MAXCMD + 3], linktarget[MAXCMD + 5], perm[11], timestr[17], uid[USERLEN + 1], gid[USERLEN + 1]; struct tm filetime; time_t t; if (lstat(name, (struct stat *) &statbuf) == -1) { // used for command_stat fprintf(client, "213-Error: %s.\n", strerror(errno)); return; } #ifdef S_ISLNK if (S_ISLNK(statbuf.st_mode)) { strcpy(perm, "lrwxrwxrwx"); temp[readlink(name, temp, sizeof(temp) - 1)] = '\0'; sprintf(linktarget, " -> %s", temp); } else { #endif strcpy(perm, "----------"); if (S_ISDIR(statbuf.st_mode)) perm[0] = 'd'; if (statbuf.st_mode & S_IRUSR) perm[1] = 'r'; if (statbuf.st_mode & S_IWUSR) perm[2] = 'w'; if (statbuf.st_mode & S_IXUSR) perm[3] = 'x'; if (statbuf.st_mode & S_IRGRP) perm[4] = 'r'; if (statbuf.st_mode & S_IWGRP) perm[5] = 'w'; if (statbuf.st_mode & S_IXGRP) perm[6] = 'x'; if (statbuf.st_mode & S_IROTH) perm[7] = 'r'; if (statbuf.st_mode & S_IWOTH) perm[8] = 'w'; if (statbuf.st_mode & S_IXOTH) perm[9] = 'x'; linktarget[0] = '\0'; #ifdef S_ISLNK } #endif memcpy(&filetime, localtime(&(statbuf.st_mtime)), sizeof(struct tm)); time(&t); if (filetime.tm_year == localtime(&t)->tm_year) mystrncpy(timestr, ctime(&(statbuf.st_mtime)) + 4, 12); else strftime(timestr, sizeof(timestr), "%b %d %G", &filetime); mygetpwuid(statbuf.st_uid, passwdfile, uid)[8] = 0; mygetpwuid(statbuf.st_gid, groupfile, gid)[8] = 0; fprintf(client, "%s %3i %-8s %-8s %8lu %s %s%s\r\n", perm, (int) statbuf.st_nlink, uid, gid, (unsigned long) statbuf.st_size, timestr, name, linktarget); }
char *LsFile(const char *name, const struct stat *st) { int ulen, glen, sz = 0; struct tm *ltime = localtime(&st->st_mtime); t_info *pw; t_info *gr; char *user, *group; char buf[1024], mode[11 + 1], tbuf[12 + 1], ubuf[11 + 1], gbuf[11 + 1]; StrMode(st->st_mode, mode); if ((pw = mygetpwuid((u_int32_t) st->st_uid)) != NULL) user = pw->name; else { (void) snprintf(ubuf, sizeof(ubuf), "%u", (unsigned int) st->st_uid); user = ubuf; } if ((gr = mygetgrgid((u_int32_t) st->st_gid)) != NULL) group = gr->name; else { (void) snprintf(gbuf, sizeof(gbuf), "%u", (unsigned int) st->st_gid); group = gbuf; } if (ltime != NULL) { if (time(0) - st->st_mtime < (365 * 24 * 60 * 60) / 2) sz = strftime(tbuf, sizeof(tbuf), "%b %e %H:%M", ltime); else sz = strftime(tbuf, sizeof(tbuf), "%b %e %Y", ltime); } if (sz == 0) tbuf[0] = '\0'; ulen = MAX((int) strlen(user), 8); glen = MAX((int) strlen(group), 8); (void) snprintf(buf, sizeof(buf), "%s %3u %-*s %-*s %8llu %s %s", mode, (unsigned int) st->st_nlink, ulen, user, glen, group, (unsigned long long int) st->st_size, tbuf, name); return (strdup(buf)); }
void bftpd_stat(char *name, FILE * client) { struct stat statbuf; char temp[MAXCMD + 3], linktarget[MAXCMD + 5], perm[11], timestr[17], uid[USERLEN + 1], gid[USERLEN + 1]; struct tm filetime; struct tm *tea_time, *local_time; time_t t; char buffer[512] = ""; if (lstat(name, (struct stat *) &statbuf) == -1) { // used for command_stat #if 0 fprintf(client, "213-Error: %s.\n", strerror(errno)); #endif snprintf( buffer, sizeof(buffer), "213-Error: %s.\n", strerror(errno) ); /*Added by yehuisheng00183935@20110702 添加ftpds功能*/ #ifdef SUPPORT_ATP_FTPDS if ( pstssldataobj != NULL ) { SSL_write(pstssldataobj, (const unsigned char *)buffer, strlen(buffer)); } else { fprintf(client, "%s", buffer ); } #else fprintf(client, "%s", buffer ); #endif /*Added by yehuisheng00183935@20110702 添加ftpds功能*/ return; } /*Added by lvxin00135113@20110425 安全代码整改*/ #ifdef S_ISLNK if (S_ISLNK(statbuf.st_mode)) { #if 0 strcpy(perm, "lrwxrwxrwx"); temp[readlink(name, temp, sizeof(temp) - 1)] = '\0'; sprintf(linktarget, " -> %s", temp); #else snprintf(perm, sizeof(perm), "%s","lrwxrwxrwx"); temp[readlink(name, temp, sizeof(temp) - 1)] = '\0'; snprintf(linktarget, sizeof(linktarget), " -> %s", temp); #endif } else { #endif #if 0 strcpy(perm, "----------"); #else snprintf(perm, sizeof(perm), "%s","----------"); #endif /*Added by lvxin00135113@20110425 安全代码整改*/ if (S_ISDIR(statbuf.st_mode)) perm[0] = 'd'; if (statbuf.st_mode & S_IRUSR) perm[1] = 'r'; if (statbuf.st_mode & S_IWUSR) perm[2] = 'w'; if (statbuf.st_mode & S_IXUSR) perm[3] = 'x'; if (statbuf.st_mode & S_IRGRP) perm[4] = 'r'; if (statbuf.st_mode & S_IWGRP) perm[5] = 'w'; if (statbuf.st_mode & S_IXGRP) perm[6] = 'x'; if (statbuf.st_mode & S_IROTH) perm[7] = 'r'; if (statbuf.st_mode & S_IWOTH) perm[8] = 'w'; if (statbuf.st_mode & S_IXOTH) perm[9] = 'x'; linktarget[0] = '\0'; #ifdef S_ISLNK } #endif /* memcpy(&filetime, localtime(&(statbuf.st_mtime)), sizeof(struct tm)); */ /*Start of ATP网络协议组 2010-4-1 14:34 forAU4D02426 by h00163136*/ /*修正问题单AU4D02426后,系统时间正确,不需该调整*/ #if 0 /*start of AU4D02390 ftp显示的时间差一年, by hh00163136, 20100208*/ statbuf.st_mtime -= g_utc_offset; /*end of AU4D02390 ftp显示的时间差一年, by hh00163136, 20100208*/ #endif /*End of ATP网络协议组 2010-4-1 14:34 by h00163136*/ local_time = gmtime(&(statbuf.st_mtime)); if (! local_time) return; memcpy(&filetime, local_time, sizeof(struct tm)); time(&t); tea_time = gmtime(&t); if (! tea_time) return; /* if (filetime.tm_year == localtime(&t)->tm_year) */ if (filetime.tm_year == tea_time->tm_year) mystrncpy(timestr, ctime(&(statbuf.st_mtime)) + 4, 12); else strftime(timestr, sizeof(timestr), "%b %d %G", &filetime); mygetpwuid(statbuf.st_uid, passwdfile, uid)[8] = 0; mygetpwuid(statbuf.st_gid, groupfile, gid)[8] = 0; #if 0 fprintf(client, "%s %3i %-8s %-8s %llu %s %s%s\r\n", perm, (int) statbuf.st_nlink, uid, gid, (unsigned long long) statbuf.st_size, timestr, name, linktarget); #endif snprintf(buffer, sizeof(buffer), "%s %3i %-8s %-8s %llu %s %s%s\r\n",perm, (int) statbuf.st_nlink, uid, gid, (unsigned long long) statbuf.st_size, timestr, name, linktarget); /*Added by yehuisheng00183935@20110702 添加ftpds功能*/ #ifdef SUPPORT_ATP_FTPDS if ( pstssldataobj != NULL ) { SSL_write(pstssldataobj, (const unsigned char *)buffer, strlen(buffer)); } else { fprintf(client, "%s", buffer ); } #else fprintf(client, "%s", buffer ); #endif /*Added by yehuisheng00183935@20110702 添加ftpds功能*/ }