1 | /* |
---|
2 | * bbftpd/bbftpd_list.c |
---|
3 | * Copyright (C) 1999, 2000, 2001, 2002 IN2P3, CNRS |
---|
4 | * bbftp@in2p3.fr |
---|
5 | * http://doc.in2p3.fr/bbftp |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | /**************************************************************************** |
---|
23 | |
---|
24 | |
---|
25 | RETURN: |
---|
26 | 0 Keep the connection open (does not mean that the directory has been |
---|
27 | successfully created) |
---|
28 | -1 Tell the calling program to close the connection |
---|
29 | |
---|
30 | bbftpd_list.c v 2.0.0 2001/02/27 - Creation of the routine. |
---|
31 | v 2.0.1 2001/04/23 - Correct indentation |
---|
32 | v 2.0.2 2001/05/04 - Change the philosophy in order |
---|
33 | to bypass CASTOR rfio_rewinddir bug |
---|
34 | v 2.1.0 2001/06/01 - Reorganise routines as in bbftp_ |
---|
35 | |
---|
36 | *****************************************************************************/ |
---|
37 | |
---|
38 | #include <bbftpd.h> |
---|
39 | |
---|
40 | #include <stdlib.h> |
---|
41 | |
---|
42 | #include <dirent.h> |
---|
43 | #include <errno.h> |
---|
44 | #include <fnmatch.h> |
---|
45 | #include <netinet/in.h> |
---|
46 | #include <bbftpd_private_log.h> |
---|
47 | #include <sys/stat.h> |
---|
48 | #include <sys/types.h> |
---|
49 | #include <utime.h> |
---|
50 | |
---|
51 | #include <bbftpd.h> |
---|
52 | #include <common.h> |
---|
53 | #include <daemon.h> |
---|
54 | #include <daemon_proto.h> |
---|
55 | #include <status.h> |
---|
56 | #include <structures.h> |
---|
57 | |
---|
58 | extern int transferoption ; |
---|
59 | extern int outcontrolsock ; |
---|
60 | extern int recvcontrolto ; |
---|
61 | extern int sendcontrolto ; |
---|
62 | |
---|
63 | int bbftpd_list(char *pattern,char *logmessage) |
---|
64 | { |
---|
65 | |
---|
66 | char *filelist ; |
---|
67 | int filelistlen ; |
---|
68 | int retcode ; |
---|
69 | char send_buffer[MINMESSLEN] ; |
---|
70 | struct message *msg ; |
---|
71 | |
---|
72 | |
---|
73 | if ( (retcode = bbftpd_retrlistdir(pattern,&filelist,&filelistlen,logmessage) ) < 0) { |
---|
74 | reply(MSG_BAD_NO_RETRY,logmessage) ; |
---|
75 | return 0 ; |
---|
76 | } else if ( retcode > 0 ) { |
---|
77 | reply(MSG_BAD,logmessage) ; |
---|
78 | return 0 ; |
---|
79 | } else { |
---|
80 | msg = (struct message *) send_buffer ; |
---|
81 | msg->code = MSG_LIST_REPL_V2 ; |
---|
82 | #ifndef WORDS_BIGENDIAN |
---|
83 | msg->msglen = ntohl(filelistlen) ; |
---|
84 | #else |
---|
85 | msg->msglen = filelistlen ; |
---|
86 | #endif |
---|
87 | if ( writemessage(outcontrolsock,send_buffer,MINMESSLEN,recvcontrolto) < 0 ) { |
---|
88 | bbftpd_log(BBFTPD_ERR,"Error sending LISTREPL_V2 part 1") ; |
---|
89 | FREE(filelist) ; |
---|
90 | return -1 ; |
---|
91 | } |
---|
92 | if (filelistlen != 0 ) { |
---|
93 | if ( writemessage(outcontrolsock,filelist,filelistlen,recvcontrolto) < 0 ) { |
---|
94 | FREE(filelist) ; |
---|
95 | bbftpd_log(BBFTPD_ERR,"Error sending filelist") ; |
---|
96 | return -1 ; |
---|
97 | } |
---|
98 | FREE(filelist) ; |
---|
99 | return 0 ; |
---|
100 | } |
---|
101 | return 0 ; |
---|
102 | } |
---|
103 | } |
---|