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