]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afs.c
Changes made by Michel Jouvin - jouvin@lal.in2p3.fr - 23/11/2000
[netatalk.git] / etc / afpd / afs.c
1 /*
2  * Copyright (c) 1990,1993 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #ifdef AFS
11
12 #include <string.h>
13 #include <sys/types.h>
14 #include <sys/syslog.h>
15 #include <netatalk/endian.h>
16 #include <netinet/in.h>
17 #include <afs/venus.h>
18 #include <afs/afsint.h>
19 #include <atalk/afp.h>
20 #include <unistd.h>
21
22 #include "globals.h"
23 #include "directory.h"
24 #include "volume.h"
25 #include "misc.h"
26
27 afs_getvolspace( vol, bfree, btotal, bsize )
28     struct vol  *vol;
29     VolSpace    *bfree, *btotal;
30     u_int32_t   *bsize;
31 {
32     struct ViceIoctl    vi;
33     struct VolumeStatus *vs;
34     char                venuspace[ sizeof( struct VolumeStatus ) + 3 ];
35     int                 total, free;
36
37     vi.in_size = 0;
38     vi.out_size = sizeof( venuspace );
39     vi.out = venuspace;
40     if ( pioctl( vol->v_path, VIOCGETVOLSTAT, &vi, 1 ) < 0 ) {
41         return( AFPERR_PARAM );
42     }
43
44     vs = (struct VolumeStatus *)venuspace;
45
46     if ( vs->PartBlocksAvail > 0 ) {
47         if ( vs->MaxQuota != 0 ) {
48 #define min(x,y)        (((x)<(y))?(x):(y))
49             free = min( vs->MaxQuota - vs->BlocksInUse, vs->PartBlocksAvail );
50         } else {
51             free = vs->PartBlocksAvail;
52         }
53     } else {
54         free = 0;
55     }
56
57     if ( vs->MaxQuota != 0 ) {
58         total = free + vs->BlocksInUse;
59     } else {
60         total = vs->PartMaxBlocks;
61     }
62
63     *bsize = 1024;
64     *bfree = (VolSpace) free * 1024;
65     *btotal = (VolSpace) total * 1024;
66
67     return( AFP_OK );
68 }
69
70 afp_getdiracl(obj, ibuf, ibuflen, rbuf, rbuflen )
71     AFPObj      *obj;
72     char        *ibuf, *rbuf;
73     int         ibuflen, *rbuflen;
74 {
75     struct ViceIoctl    vi;
76     struct vol          *vol;
77     struct dir          *dir;
78     char                *path;
79     u_int32_t           did;
80     u_int16_t           vid;
81
82     ibuf += 2;
83     memcpy( &vid, ibuf, sizeof( vid ));
84     ibuf += sizeof( short );
85     if (( vol = getvolbyvid( vid )) == NULL ) {
86         *rbuflen = 0;
87         return( AFPERR_PARAM );
88     }
89
90     memcpy( &did, ibuf, sizeof( did ));
91     ibuf += sizeof( int );
92     if (( dir = dirsearch( vol, did )) == NULL ) {
93         *rbuflen = 0;
94         return( AFPERR_NOOBJ );
95     }
96
97     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
98         *rbuflen = 0;
99         return( AFPERR_NOOBJ );
100     }
101     if ( *path != '\0' ) {
102         *rbuflen = 0;
103         return( AFPERR_BITMAP );
104     }
105
106     vi.in_size = 0;
107     vi.out_size = *rbuflen;
108     vi.out = rbuf;
109     if ( pioctl( ".", VIOCGETAL, &vi, 1 ) < 0 ) {
110         *rbuflen = 0;
111         return( AFPERR_PARAM );
112     }
113     *rbuflen = strlen( vi.out ) + 1;
114     return( AFP_OK );
115 }
116
117 /*
118  * Calculate the mode for a directory in AFS.  First, make sure the
119  * directory is in AFS.  Could probably use something less heavy than
120  * VIOCGETAL.  If the directory is on AFS, use access() calls to
121  * estimate permission, a la mdw.
122  */
123 afsmode( path, ma, dir )
124     char                *path;
125     struct maccess      *ma;
126     struct dir          *dir;
127 {
128     struct ViceIoctl    vi;
129     char                buf[ 1024 ];
130
131     if (( dir->d_flags & DIRF_FSMASK ) == DIRF_NOFS ) {
132         vi.in_size = 0;
133         vi.out_size = sizeof( buf );
134         vi.out = buf;
135         if ( pioctl( path, VIOCGETAL, &vi, 1 ) < 0 ) {
136             dir->d_flags |= DIRF_UFS;
137         } else {
138             dir->d_flags |= DIRF_AFS;
139         }
140     }
141
142     if (( dir->d_flags & DIRF_FSMASK ) != DIRF_AFS ) {
143         return;
144     }
145
146     accessmode( upath, &ma, dir );
147
148     return;
149 }
150
151 extern struct dir       *curdir;
152 /*
153  * cmd | 0 | vid | did | pathtype | pathname | 0 | acl
154  */
155 afp_setdiracl(obj, ibuf, ibuflen, rbuf, rbuflen )
156     AFPObj      *obj;
157     char        *ibuf, *rbuf;
158     int         ibuflen, *rbuflen;
159 {
160     struct ViceIoctl    vi;
161     struct vol          *vol;
162     struct dir          *dir;
163     char                *path, *iend;
164     u_int32_t           did;
165     u_int16_t           vid;
166
167     *rbuflen = 0;
168     iend = ibuf + ibuflen;
169     ibuf += 2;
170     memcpy( &vid, ibuf, sizeof( vid ));
171     ibuf += sizeof( short );
172     if (( vol = getvolbyvid( vid )) == NULL ) {
173         *rbuflen = 0;
174         return( AFPERR_PARAM );
175     }
176
177     memcpy( &did, ibuf, sizeof( did ));
178     ibuf += sizeof( int );
179     if (( dir = dirsearch( vol, did )) == NULL ) {
180         *rbuflen = 0;
181         return( AFPERR_NOOBJ );
182     }
183
184     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
185         *rbuflen = 0;
186         return( AFPERR_NOOBJ );
187     }
188     if ( *path != '\0' ) {
189         *rbuflen = 0;
190         return( AFPERR_BITMAP );
191     }
192
193     if ((int)ibuf & 1 ) {
194         ibuf++;
195     }
196
197     vi.in_size = iend - ibuf;
198     vi.in = ibuf;
199     vi.out_size = 0;
200
201     if ( pioctl( ".", VIOCSETAL, &vi, 1 ) < 0 ) {
202         *rbuflen = 0;
203         return( AFPERR_PARAM );
204     }
205     pioctl( ".AppleDouble", VIOCSETAL, &vi, 1 );
206     if ( curdir->d_did  == DIRDID_ROOT ) {
207         pioctl( ".AppleDesktop", VIOCSETAL, &vi, 1 );
208     }
209
210     return( AFP_OK );
211 }
212
213
214 #ifdef UAM_AFSKRB
215
216 #include <krb.h>
217 #include <des.h>
218 #include <afs/kauth.h>
219 #include <afs/kautils.h>
220
221 extern C_Block          seskey;
222 extern Key_schedule     seskeysched;
223
224 afp_afschangepw(obj, ibuf, ibuflen, rbuf, rbuflen )
225     AFPObj      *obj;
226     char        *ibuf, *rbuf;
227     int         ibuflen, *rbuflen;
228 {
229     char        name[ MAXKTCNAMELEN ], instance[ MAXKTCNAMELEN ];
230     char        realm[ MAXKTCREALMLEN ];
231     char        oldpw[ 9 ], newpw[ 9 ];
232     int         len, rc;
233     u_int16_t   clen;
234     struct ktc_encryptionKey    oldkey, newkey;
235     struct ktc_token            adtok;
236     struct ubik_client          *conn;
237
238     *rbuflen = 0;
239     ++ibuf;
240     len = (unsigned char) *ibuf++;
241     ibuf[ len ] = '\0';
242     *name = *instance = *realm = '\0';
243     ka_ParseLoginName( ibuf, name, instance, realm );
244     ucase( realm );
245     if ( *realm == '\0' ) {
246         if ( krb_get_lrealm( realm, 1 ) != KSUCCESS ) {
247             syslog( LOG_ERR, "krb_get_lrealm failed" );
248             return( AFPERR_BADUAM );
249         }
250     }
251
252     if ( strlen( name ) < 2 || strlen( name ) > 18 ) {
253         return( AFPERR_PARAM );
254     }
255     ibuf += len;
256
257     memcpy( &clen, ibuf, sizeof( clen ));
258     clen = ntohs( clen );
259     if ( clen % 8 != 0 ) {
260         return( AFPERR_PARAM );
261     }
262
263     ibuf += sizeof( short );
264     pcbc_encrypt((C_Block *)ibuf, (C_Block *)ibuf,
265             clen, seskeysched, seskey, DES_DECRYPT );
266
267     len = (unsigned char) *ibuf++;
268     if ( len > 8 ) {
269         return( AFPERR_PARAM );
270     }
271     memset( oldpw, 0, sizeof( oldpw ));
272     memcpy( oldpw, ibuf, len );
273     ibuf += len;
274     oldpw[ len ] = '\0';
275
276     len = (unsigned char) *ibuf++;
277     if ( len > 8 ) {
278         return( AFPERR_PARAM );
279     }
280     memset( newpw, 0, sizeof( newpw ));
281     memcpy( newpw, ibuf, len );
282     ibuf += len;
283     newpw[ len ] = '\0';
284
285     syslog( LOG_INFO,
286         "changing password for <%s>.<%s>@<%s>", name, instance, realm );
287
288     ka_StringToKey( oldpw, realm, &oldkey );
289     memset( oldpw, 0, sizeof( oldpw ));
290     ka_StringToKey( newpw, realm, &newkey );
291     memset( newpw, 0, sizeof( newpw ));
292
293     rc = ka_GetAdminToken( name, instance, realm, &oldkey, 60, &adtok, 0 );
294     memset( &oldkey, 0, sizeof( oldkey ));
295     switch ( rc ) {
296         case 0:
297             break;
298         case KABADREQUEST:
299             memset( &newkey, 0, sizeof( newkey ));
300             return( AFPERR_NOTAUTH );
301         default:
302             memset( &newkey, 0, sizeof( newkey ));
303             return( AFPERR_BADUAM );
304     }
305     if ( ka_AuthServerConn( realm, KA_MAINTENANCE_SERVICE, &adtok, &conn )
306                 != 0 ) {
307         memset( &newkey, 0, sizeof( newkey ));
308         return( AFPERR_BADUAM );
309     }
310
311     rc = ka_ChangePassword( name, instance, conn, 0, &newkey );
312     memset( &newkey, 0, sizeof( newkey ));
313     if ( rc != 0 ) {
314         return( AFPERR_BADUAM );
315     }
316
317     syslog( LOG_DEBUG, "password changed succeeded" );
318     return( AFP_OK );
319 }
320
321 #endif UAM_AFSKRB
322 #endif AFS