1 | /* |
---|
2 | * bbftpd/bbftpd_private_user.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 | |
---|
26 | bbftpd_private_user.c v 2.1.0 2001/05/21 - Routines creation |
---|
27 | |
---|
28 | *****************************************************************************/ |
---|
29 | #include <netinet/in.h> |
---|
30 | #include <utime.h> |
---|
31 | |
---|
32 | #include <bbftpd.h> |
---|
33 | #include <daemon_proto.h> |
---|
34 | #include <structures.h> |
---|
35 | #include <syslog.h> |
---|
36 | |
---|
37 | #include <bbftpd_private_user.h> |
---|
38 | |
---|
39 | extern char currentusername[MAXLEN] ; |
---|
40 | |
---|
41 | #ifdef NDG_PYTHON_EMBED |
---|
42 | int bbftpd_private_auth_callback(char *logmessage); |
---|
43 | #endif |
---|
44 | |
---|
45 | /******************************************************************************* |
---|
46 | ** bbftpd_private_auth : * |
---|
47 | ** * |
---|
48 | ** Routine to do the private authentication. This routine just have to * |
---|
49 | ** send or to receive private data to the bbftpd daemon. For that it will * |
---|
50 | ** use the two routines : * |
---|
51 | ** bbftpd_private_send * |
---|
52 | ** bbftpd_private_recv * |
---|
53 | ** The reception of the OK or BAD message will be done by the calling * |
---|
54 | ** routine, so if this routine has no check to do (for example just * |
---|
55 | ** sending username and password) it will just call bbftp_private_send * |
---|
56 | ** twice and let the calling program check if it is OK or BAD. * |
---|
57 | ** * |
---|
58 | ** The bbftp_private_send routine has to be called with the following * |
---|
59 | ** parameters: * |
---|
60 | ** * |
---|
61 | ** int bbftpd_private_send(char *buffertosend,int buffertosendlength, * |
---|
62 | ** char *logmessage) * |
---|
63 | ** char *buffertosend = string to be send to the daemon * |
---|
64 | ** int buffertosendlength = length of the string * |
---|
65 | ** char *logmessage * |
---|
66 | ** * |
---|
67 | ** and return 0 in case of success, -1 in case of error with logmessage * |
---|
68 | ** filled * |
---|
69 | ** * |
---|
70 | ** The bbftpd_private_recv routine has to be called with the following * |
---|
71 | ** parameters: * |
---|
72 | ** * |
---|
73 | ** int bbftpd_private_recv(char *buffertorecv,int lengthtoreceive, * |
---|
74 | ** char *logmessage) * |
---|
75 | ** char *buffertorecv = string to be send to the daemon * |
---|
76 | ** int lengthtorecv = length to be received * |
---|
77 | ** char *logmessage * |
---|
78 | ** * |
---|
79 | ** and return number of byte received in case of success, -1 in case of * |
---|
80 | ** error with logmessage filled * |
---|
81 | ** It is the duty of the programmer to take care that the buffer is large * |
---|
82 | ** enought * |
---|
83 | ** * |
---|
84 | ** * |
---|
85 | ** OUPUT variable : * |
---|
86 | ** logmessage : to write the error message in case of error * |
---|
87 | ** * |
---|
88 | ** GLOBAL VARIABLE USED : * |
---|
89 | ** * |
---|
90 | ** * |
---|
91 | ** RETURN: * |
---|
92 | ** -1 Unrecoverable error * |
---|
93 | ** 0 OK * |
---|
94 | ** * |
---|
95 | *******************************************************************************/ |
---|
96 | |
---|
97 | int bbftpd_private_auth(char *logmessage) |
---|
98 | { |
---|
99 | char msg[NDG_MESSAGE_LEN]; |
---|
100 | /* Send version verification message. */ |
---|
101 | if (bbftpd_private_recv(msg, NDG_MESSAGE_LEN, logmessage) == -1) { |
---|
102 | return -1; |
---|
103 | } |
---|
104 | else { |
---|
105 | syslog(LOG_DEBUG, "Received auth message: %s", msg); |
---|
106 | } |
---|
107 | |
---|
108 | #ifdef NDG_PYTHON_EMBED |
---|
109 | return bbftpd_private_auth_callback(logmessage); |
---|
110 | #else |
---|
111 | return 0 ; |
---|
112 | #endif |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | #ifdef NDG_AUTH |
---|
117 | |
---|
118 | /* |
---|
119 | ** bbftpd_private_authz_control : |
---|
120 | ** |
---|
121 | ** Routine to authorise bbftp control commands. |
---|
122 | ** |
---|
123 | ** INPUT variables: |
---|
124 | ** msgcode : The message code from struct message |
---|
125 | ** transferoptions : TROPT_* options |
---|
126 | ** path : path to apply command to |
---|
127 | ** |
---|
128 | ** OUTPUT variables: |
---|
129 | ** logmessage : to write the error message in case of failure |
---|
130 | ** |
---|
131 | ** RETURN: |
---|
132 | ** -1 Authorisation failed |
---|
133 | ** 0 OK |
---|
134 | ** |
---|
135 | ** |
---|
136 | */ |
---|
137 | int bbftpd_private_authz_control(int msgcode, int transferoption, char *path, char *logmessage) |
---|
138 | { |
---|
139 | |
---|
140 | switch (msgcode) { |
---|
141 | case MSG_CHDIR_V2: |
---|
142 | syslog(LOG_DEBUG, "Authz: MSG_DIR 0x%x %s", transferoption, path); |
---|
143 | break; |
---|
144 | case MSG_LIST_V2: |
---|
145 | syslog(LOG_DEBUG, "Authz: MSG_LIST_V2 0x%x %s", transferoption, path); |
---|
146 | break; |
---|
147 | case MSG_MKDIR_V2: |
---|
148 | syslog(LOG_DEBUG, "Authz: MSG_MKDIR_V2 0x%x %s", transferoption, path); |
---|
149 | break; |
---|
150 | case MSG_RM: |
---|
151 | syslog(LOG_DEBUG, "Authz: MSG_RM 0x%x %s", transferoption, path); |
---|
152 | break; |
---|
153 | case MSG_STAT: |
---|
154 | syslog(LOG_DEBUG, "Authz: MSG_STAT 0x%x %s", transferoption, path); |
---|
155 | break; |
---|
156 | case MSG_DF: |
---|
157 | syslog(LOG_DEBUG, "Authz: MSG_DF 0x%x %s", transferoption, path); |
---|
158 | break; |
---|
159 | default: |
---|
160 | sprintf(logmessage, "Unrecognised message to authorise %d", msgcode); |
---|
161 | return -1; |
---|
162 | } |
---|
163 | |
---|
164 | return 0; |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | /* |
---|
169 | ** bbftpd_private_authz_retr : |
---|
170 | ** |
---|
171 | ** Routine to authorise file retrieve requests. |
---|
172 | ** |
---|
173 | ** INPUT variables: |
---|
174 | ** path: the file to retrieve |
---|
175 | ** |
---|
176 | ** OUTPUT variables: |
---|
177 | ** logmessage : to write the error message in case of failure |
---|
178 | ** |
---|
179 | ** RETURN: |
---|
180 | ** -1 Authorisation failed |
---|
181 | ** 0 OK |
---|
182 | ** |
---|
183 | */ |
---|
184 | int bbftpd_private_authz_retr(char *path, char *logmessage) |
---|
185 | { |
---|
186 | syslog(LOG_DEBUG, "Authz: RETR %s", path); |
---|
187 | return 0; |
---|
188 | } |
---|
189 | |
---|
190 | /* |
---|
191 | ** bbftpd_private_authz_store : |
---|
192 | ** |
---|
193 | ** Routine to authorise file store requests. |
---|
194 | ** |
---|
195 | ** INPUT variables: |
---|
196 | ** path: the file to store |
---|
197 | ** |
---|
198 | ** OUTPUT variables: |
---|
199 | ** logmessage : to write the error message in case of failure |
---|
200 | ** |
---|
201 | ** RETURN: |
---|
202 | ** -1 Authorisation failed |
---|
203 | ** 0 OK |
---|
204 | ** |
---|
205 | */ |
---|
206 | |
---|
207 | int bbftpd_private_authz_store(char *path, char *logmessage) |
---|
208 | { |
---|
209 | syslog(LOG_DEBUG, "Authz: STORE %s", path); |
---|
210 | return 0; |
---|
211 | } |
---|
212 | #endif // NDG_AUTH |
---|