]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/passwd.c
Fixed Netatalk's version number (pointed out by Olaf).
[netatalk.git] / etc / afpd / passwd.c
1 /*
2  * $Id: passwd.c,v 1.5 2001-12-03 05:03:38 jmarcus 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
33 /* STDC check */
34 #if STDC_HEADERS
35 #include <string.h>
36 #else /* STDC_HEADERS */
37 #ifndef HAVE_STRCHR
38 #define strchr index
39 #define strrchr index
40 #endif /* HAVE_STRCHR */
41 char *strchr (), *strrchr ();
42 #ifndef HAVE_MEMCPY
43 #define memcpy(d,s,n) bcopy ((s), (d), (n))
44 #define memmove(d,s,n) bcopy ((s), (d), (n))
45 #endif /* ! HAVE_MEMCPY */
46 #endif /* STDC_HEADERS */
47
48 #include <r/xdr.h>
49 #include <r/r.h>
50 #include <afs/comauth.h>
51 #include <sys/types.h>
52 #include <netinet/in.h>
53 #include <afs/cellconfig.h>
54
55 #define DB_PASSWD   0
56
57 extern int r_errno;
58
59 afs_changepw( ibuf, ibuflen, rbuf, rbuflen )
60 char    *ibuf, *rbuf;
61 int             ibuflen, *rbuflen;
62 {
63     char        cell[ MAXCELLCHARS ], name[ 20 ], oldpw[ 10 ], newpw[ 10 ];
64     char        *p;
65     int         len;
66     u_int16_t   clen;
67
68     len = (unsigned char )*ibuf++;
69     ibuf[ len ] = '\0';
70     if (( p = strchr( ibuf, '@' )) != NULL ) {
71         *p++ = '\0';
72         strcpy( cell, p );
73         ucase( cell );
74     } else {
75         if ( GetLocalCellName() != CCONF_SUCCESS ) {
76             *rbuflen = 0;
77             return( AFPERR_BADUAM );
78         }
79         strcpy( cell, LclCellName );
80     }
81
82     if ( strlen( ibuf ) > 20 ) {
83         *rbuflen = 0;
84         return( AFPERR_PARAM );
85     }
86     strcpy( name, ibuf );
87     ibuf += len;
88
89
90     if (U_InitRPC() != 0) {
91         *rbuflen = 0;
92         return( AFPERR_BADUAM );
93     }
94
95     memcpy( &clen, ibuf, sizeof( clen ));
96     ibuf += sizeof( short );
97     pcbc_encrypt((C_Block *)ibuf, (C_Block *)ibuf,
98                  clen, seskeysched, seskey, 0 );
99
100     len = (unsigned char) *ibuf++;
101     if ( len > 9 ) {
102         *rbuflen = 0;
103         return( AFPERR_PARAM );
104     }
105     memcpy( oldpw, ibuf, len );
106     oldpw[ len ] = '\0';
107
108     len = (unsigned char) *ibuf++;
109     if ( len > 9 ) {
110         *rbuflen = 0;
111         return( AFPERR_PARAM );
112     }
113     memcpy( newpw, ibuf, len );
114     newpw[ len ] = '\0';
115
116     rc = U_CellChangePassword( name, newpw, name, oldpw, cell ) != 0 ) {
117
118         if ( rc != 0 ) {
119             *rbuflen = 0;
120             if ( rc < 0 && r_errno = R_ERROR ) {
121                 return( AFPERR_NOTAUTH );
122             } else {
123                 return( AFPERR_BADUAM );
124             }
125         }
126
127         return( AFP_OK );
128     }