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