]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/passwd.c
Initial revision
[netatalk.git] / etc / afpd / passwd.c
1 /*
2  * Copyright (c) 1990,1991 Regents of The University of Michigan.
3  * All Rights Reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation, and that the name of The University
10  * of Michigan not be used in advertising or publicity pertaining to
11  * distribution of the software without specific, written prior
12  * permission. This software is supplied as is without expressed or
13  * implied warranties of any kind.
14  *
15  *      Research Systems Unix Group
16  *      The University of Michigan
17  *      c/o Mike Clark
18  *      535 W. William Street
19  *      Ann Arbor, Michigan
20  *      +1-313-763-0525
21  *      netatalk@itd.umich.edu
22  */
23
24 #include <itc.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <r/xdr.h>
28 #include <r/r.h>
29 #include <afs/comauth.h>
30 #include <sys/types.h>
31 #include <netinet/in.h>
32 #include <afs/cellconfig.h>
33
34 #define DB_PASSWD   0
35
36 extern int r_errno;
37
38 afs_changepw( ibuf, ibuflen, rbuf, rbuflen )
39     char        *ibuf, *rbuf;
40     int         ibuflen, *rbuflen;
41 {
42     char        cell[ MAXCELLCHARS ], name[ 20 ], oldpw[ 10 ], newpw[ 10 ];
43     char        *p;
44     int         len;
45     u_int16_t   clen;
46
47     len = (unsigned char )*ibuf++;
48     ibuf[ len ] = '\0';
49     if (( p = strchr( ibuf, '@' )) != NULL ) {
50         *p++ = '\0';
51         strcpy( cell, p );
52         ucase( cell );
53     } else {
54         if ( GetLocalCellName() != CCONF_SUCCESS ) {
55             *rbuflen = 0;
56             return( AFPERR_BADUAM );
57         }
58         strcpy( cell, LclCellName );
59     }
60
61     if ( strlen( ibuf ) > 20 ) {
62         *rbuflen = 0;
63         return( AFPERR_PARAM );
64     }
65     strcpy( name, ibuf );
66     ibuf += len;
67
68
69     if (U_InitRPC() != 0) {
70         *rbuflen = 0;
71         return( AFPERR_BADUAM );
72     }
73
74     memcpy( &clen, ibuf, sizeof( clen ));
75     ibuf += sizeof( short );
76     pcbc_encrypt((C_Block *)ibuf, (C_Block *)ibuf,
77             clen, seskeysched, seskey, 0 );
78
79     len = (unsigned char) *ibuf++;
80     if ( len > 9 ) {
81         *rbuflen = 0;
82         return( AFPERR_PARAM );
83     }
84     memcpy( oldpw, ibuf, len );
85     oldpw[ len ] = '\0';
86
87     len = (unsigned char) *ibuf++;
88     if ( len > 9 ) {
89         *rbuflen = 0;
90         return( AFPERR_PARAM );
91     }
92     memcpy( newpw, ibuf, len );
93     newpw[ len ] = '\0';
94
95     rc = U_CellChangePassword( name, newpw, name, oldpw, cell ) != 0 ) {
96
97     if ( rc != 0 ) {
98         *rbuflen = 0;
99         if ( rc < 0 && r_errno = R_ERROR ) {
100             return( AFPERR_NOTAUTH );
101         } else {
102             return( AFPERR_BADUAM );
103         }
104     }
105
106     return( AFP_OK );
107 }