source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_user.c @ 983

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_user.c@983
Revision 983, 8.1 KB checked in by spascoe, 13 years ago (diff)

Added the autorisation hook bbftpd_private_authz. It appears to be called
correctly for a dir command.

Line 
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
39extern char currentusername[MAXLEN] ;
40
41/*******************************************************************************
42** bbftpd_private_auth :                                                       *
43**                                                                             *
44**      Routine to do the private authentication. This routine just have to    *
45**      send or to receive private data to the bbftpd daemon. For that it will *
46**      use the two routines :                                                 *
47**          bbftpd_private_send                                                *
48**          bbftpd_private_recv                                                *
49**      The reception of the OK or BAD message will be done by the calling     *
50**      routine, so if this routine has no check to do (for example just       *
51**      sending username and password) it will just call bbftp_private_send    *
52**      twice and let the calling program check if it is OK or BAD.            *
53**                                                                             *
54**      The bbftp_private_send routine has to be called with the following     *
55**      parameters:                                                            *
56**                                                                             *
57**      int bbftpd_private_send(char *buffertosend,int buffertosendlength,     *
58**                             char *logmessage)                               *
59**          char    *buffertosend = string to be send to the daemon            *
60**          int     buffertosendlength = length of the string                  *
61**          char    *logmessage                                                *
62**                                                                             *
63**      and return 0 in case of success, -1 in case of error with logmessage   *
64**      filled                                                                 *
65**                                                                             *
66**      The bbftpd_private_recv routine has to be called with the following    *
67**      parameters:                                                            *
68**                                                                             *
69**      int bbftpd_private_recv(char *buffertorecv,int lengthtoreceive,        *
70**                             char *logmessage)                               *
71**          char    *buffertorecv = string to be send to the daemon            *
72**          int     lengthtorecv = length to be received                       *
73**          char    *logmessage                                                *
74**                                                                             *
75**      and return number of byte received in case of success, -1 in case of   *
76**      error with logmessage filled                                           *
77**      It is the duty of the programmer to take care that the buffer is large *
78**      enought                                                                *
79**                                                                             *
80**                                                                             *
81**      OUPUT variable :                                                       *
82**          logmessage :  to write the error message in case of error          *
83**                                                                             *
84**      GLOBAL VARIABLE USED :                                                 *
85**                                                                             *
86**                                                                             *
87**      RETURN:                                                                *
88**          -1  Unrecoverable error                                            *
89**           0  OK                                                             *
90**                                                                             *
91*******************************************************************************/
92
93int bbftpd_private_auth(char *logmessage)
94{
95  char msg[NDG_MESSAGE_LEN];
96  /* Send version verification message.  */
97  if (bbftpd_private_recv(msg, NDG_MESSAGE_LEN, logmessage) == -1) {
98    return -1;
99  }
100  else {
101    syslog(LOG_INFO, "Received auth message: %s", msg);
102  }
103
104  return 0 ;
105}
106
107
108#ifdef NDG_AUTH
109
110/*
111 * bbftpd_private_init :
112 *
113 *     Routine to initialise private authentication.  This function will be
114 *     called before bbftpd begins listening for connections and therefore
115 *     before the fork() that occurs when a client connects.
116 *
117 *     OUTPUT variable :
118 *          logmessage :  to write the error message in case of error
119 *
120 *     RETURN:
121 *         -1  Unrecoverable error
122 *          0  OK
123 *
124 */
125
126int bbftpd_private_init(char *logmessage)
127{
128  syslog(LOG_INFO, "initialising private authentication");
129  return 0;
130}
131
132/*
133 * bbftpd_private_finalise :
134 *
135 *     Routine to clean up the private authentication infrastructure when the
136 *     daemon exits.  This function is the counterpart of bbftpd_private_init and
137 *     will be called from the daemon process during exit.  NOTE: it will not
138 *     be aware of any actions of child processes.
139 *
140 */
141
142void bbftpd_private_finalise(void)
143{
144  syslog(LOG_INFO, "finalising private authentication in server");
145  return;
146}
147
148/*
149 * bbftpd_private_auth_finalise :
150 *
151 *     Routine to clean up the private authentication infrastructure for each child.
152 *     This function is the counterpart of bbftpd_private_auth and will be called from
153 *     each child of the daemon during exit.
154 *
155 */
156
157void bbftpd_private_auth_finalise(void)
158{
159  syslog(LOG_INFO, "finalising private authentication in connection");
160  return;
161}
162
163/*
164** bbftpd_private_authz :
165**
166**    Routine to authorise individual bbftp commands.  The function must return
167**    OK for the command to proceed.
168**
169**    INPUT variables:
170**        msgcode : The message code from struct message
171**        msgstruct : A pointer to a bbftpd structure dependent on the message type (see below)
172**
173**    OUTPUT variables:
174**        logmessage : to write the error message in case of failure
175**
176**    RETURN:
177**       -1  Authorisation failed
178**        0  OK
179**
180**  msgstruct should be cast to the appropriate structure from structures.h
181**  acording to msgcode:
182**
183**    MSG_CHDIR_V2  : struct mess_dir
184**    MSG_CHUMASK   : struct mess_int
185**    MSG_MKLIST_V2 : struct mess_dir
186**    MSG_MKDIR_V2  : struct mess_dir
187**    MSG_RM        : struct mess_dir
188**    MSG_STAT      : struct mess_dir
189**    MSG_DF        : struct mess_dir
190**    MSG_RETR_V2   : struct mess_store_v2
191**    MSG_STORE_V2  : struct mess_store_v2
192**
193*/
194int bbftpd_private_authz(int msgcode, void *msgstruct, char *logmessage)
195{
196
197  // For test purposes just log the authorisation request
198  syslog(LOG_INFO, "Authorisation request: %d", msgcode);
199  return 0;
200
201}
202
203
204#endif // NDG_AUTH
Note: See TracBrowser for help on using the repository browser.