summaryrefslogtreecommitdiffstats
path: root/src/kadmin/server/adm_kpasswd.c
blob: ce7b308bf4f5de04c02842f95755b51c7bd629f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * kadmin/server/adm_kpasswd.c
 *
 * Copyright 1988 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 *
 */

/*
 * Sandia National Laboratories also makes no representations about the
 * suitability of the modifications, or additions to this software for
 * any purpose.  It is provided "as is" without express or implied warranty.
 */


/*
  adm_kpasswd.c
*/

#include <sys/types.h>
#include <syslog.h>
#include <sys/wait.h>
#include <stdio.h>
#include <com_err.h>

#include <sys/socket.h>
#include <netinet/in.h>
#ifndef hpux
#include <arpa/inet.h>
#endif
 
#include <krb5/krb5.h>
#include <krb5/kdb.h>
#include <krb5/ext-proto.h>
#include <krb5/los-proto.h>
#include <krb5/adm_defs.h>
#include "adm_extern.h"
 
extern krb5_encrypt_block master_encblock;
extern krb5_keyblock master_keyblock;
 
struct cpw_keyproc_arg {
    krb5_keyblock *key;
};
 
krb5_error_code
adm5_kpasswd(context, prog, request_type, client_creds, retbuf, otype)
    krb5_context context;
    char *prog;
    kadmin_requests *request_type;
    krb5_ticket *client_creds;
    char *retbuf;
    int *otype;
{
    char completion_msg[520];
    krb5_error_code retval;

    switch (request_type->oper_code) {
    case CHGOPER:
	*otype = 3;
	syslog(LOG_AUTH | LOG_INFO,
	       "adm_kpasswd: kpasswd change received");
	retval = adm5_change(context, "adm5_kpasswd", 
			     client_server_info.client,
			     client_creds);

	switch(retval) {
	case 0:
	    retbuf[0] = KPASSWD;
	    retbuf[1] = CHGOPER;
	    retbuf[2] = KPASSGOOD;
	    retbuf[3] = '\0';
	    break;

	case 1:
	    retbuf[0] = KPASSWD;
	    retbuf[1] = CHGOPER;
	    retbuf[2] = KPASSBAD;
	    retbuf[3] = '\0';
	    sprintf((char *)retbuf +3, "%s", 
		    kadmind_kpasswd_response[retval]);
	    sprintf(completion_msg,
		    "kpasswd change from %s FAILED: %s", 
		    inet_ntoa(client_server_info.client_name.sin_addr),
		    kadmind_kpasswd_response[retval]);
	    syslog(LOG_AUTH | LOG_INFO, completion_msg);
	    goto finish;

	default:
	    retbuf[0] = KPASSWD;
	    retbuf[1] = CHGOPER;
	    retbuf[2] = KUNKNOWNERR;
	    retbuf[3] = '\0';
	    sprintf(completion_msg, "kpasswd change from %s FAILED", 
		    inet_ntoa(client_server_info.client_name.sin_addr));
	    syslog(LOG_AUTH | LOG_INFO, completion_msg);
	    retval = 255;
	    goto finish;
	}		/* switch (retval) */
	break;

    default:
	retbuf[0] = KPASSWD;
	retbuf[1] = KUNKNOWNOPER;
	retbuf[2] = '\0';
	sprintf(completion_msg, "kpasswd %s from %s FAILED", 
		"Unknown or Non-Implemented Operation Type!",
		inet_ntoa(client_server_info.client_name.sin_addr ));
	syslog(LOG_AUTH | LOG_INFO, completion_msg);
	retval = 255;
	goto finish;
    }			/* switch (request_type->oper_code) */
    
finish:
	return(retval);
}