]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/passwd.c
03b352608af301187a46c599e269a34111ba1511
[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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <itc.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <r/xdr.h>
32 #include <r/r.h>
33 #include <afs/comauth.h>
34 #include <sys/types.h>
35 #include <netinet/in.h>
36 #include <afs/cellconfig.h>
37
38 #define DB_PASSWD   0
39
40 extern int r_errno;
41
42 afs_changepw( ibuf, ibuflen, rbuf, rbuflen )
43     char        *ibuf, *rbuf;
44     int         ibuflen, *rbuflen;
45 {
46     char        cell[ MAXCELLCHARS ], name[ 20 ], oldpw[ 10 ], newpw[ 10 ];
47     char        *p;
48     int         len;
49     u_int16_t   clen;
50
51     len = (unsigned char )*ibuf++;
52     ibuf[ len ] = '\0';
53     if (( p = strchr( ibuf, '@' )) != NULL ) {
54         *p++ = '\0';
55         strcpy( cell, p );
56         ucase( cell );
57     } else {
58         if ( GetLocalCellName() != CCONF_SUCCESS ) {
59             *rbuflen = 0;
60             return( AFPERR_BADUAM );
61         }
62         strcpy( cell, LclCellName );
63     }
64
65     if ( strlen( ibuf ) > 20 ) {
66         *rbuflen = 0;
67         return( AFPERR_PARAM );
68     }
69     strcpy( name, ibuf );
70     ibuf += len;
71
72
73     if (U_InitRPC() != 0) {
74         *rbuflen = 0;
75         return( AFPERR_BADUAM );
76     }
77
78     memcpy( &clen, ibuf, sizeof( clen ));
79     ibuf += sizeof( short );
80     pcbc_encrypt((C_Block *)ibuf, (C_Block *)ibuf,
81             clen, seskeysched, seskey, 0 );
82
83     len = (unsigned char) *ibuf++;
84     if ( len > 9 ) {
85         *rbuflen = 0;
86         return( AFPERR_PARAM );
87     }
88     memcpy( oldpw, ibuf, len );
89     oldpw[ len ] = '\0';
90
91     len = (unsigned char) *ibuf++;
92     if ( len > 9 ) {
93         *rbuflen = 0;
94         return( AFPERR_PARAM );
95     }
96     memcpy( newpw, ibuf, len );
97     newpw[ len ] = '\0';
98
99     rc = U_CellChangePassword( name, newpw, name, oldpw, cell ) != 0 ) {
100
101     if ( rc != 0 ) {
102         *rbuflen = 0;
103         if ( rc < 0 && r_errno = R_ERROR ) {
104             return( AFPERR_NOTAUTH );
105         } else {
106             return( AFPERR_BADUAM );
107         }
108     }
109
110     return( AFP_OK );
111 }