2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* This file contains the code to handle UDP requests to the authentication
11 server using the MIT Kerberos protocol for obtaining tickets. It will only
12 handle authentication and get ticket requests to provide read-only protocol
13 level compatibility with the standard Kerberos servers. */
15 #include <afsconfig.h>
16 #include <afs/param.h>
21 #ifdef IGNORE_SOME_GCC_WARNINGS
22 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
26 #include <afs/errmap_nt.h>
30 #include <hcrypto/des.h>
32 #include <afs/com_err.h>
37 #include <rx/rxkad_convert.h>
43 #include "kauth_internal.h"
45 #include "prot.h" /* protocol definitions */
47 #include "afs/audit.h"
49 #include "kadatabase.h"
51 /* my kerberos error codes */
52 #define KERB_ERR_BAD_MSG_TYPE 99
53 #define KERB_ERR_BAD_LIFETIME 98
54 #define KERB_ERR_NONNULL_REALM 97
55 #define KERB_ERR_PKT_LENGTH 96
56 #define KERB_ERR_TEXT_LENGTH 95
58 #define KDC_GEN_ERR 20
62 #define closesocket close
65 int krb_udp_debug
= 0;
67 static int sock_kerb
= -1; /* the socket we're using */
68 static int sock_kerb5
= -1; /* the socket we're using */
72 struct sockaddr_in from
;
78 char *rest
; /* remaining bytes of packet */
79 char data
[MAX_PKT_LEN
];
82 extern char *lastOperation
;
85 char udpAuthPrincipal
[256];
86 char udptgsPrincipal
[256];
87 char udptgsServerPrincipal
[256];
89 #define putstr(name) if ((slen = strlen(name)) >= MAXKTCNAMELEN) return -1;\
90 else strcpy (answer, name), answer += slen+1
91 #define putint(num) num = htonl(num), \
92 memcpy(answer, &num, sizeof(afs_int32)), \
93 answer += sizeof(afs_int32)
95 #define getstr(name) if ((slen = strlen(packet)) >= sizeof(name)) return -1;\
96 strcpy (name, packet), packet += slen+1
97 #define getint(num) memcpy(&num, packet, sizeof(afs_int32)), \
98 num = ktohl (byteOrder, num), \
99 packet += sizeof(afs_int32)
101 /* this is just to close the log every five minutes to rm works */
103 int fiveminutes
= 300;
106 FiveMinuteCheckLWP(void *unused
)
109 printf("start 5 min check lwp\n");
112 IOMGR_Sleep(fiveminutes
);
113 /* close the log so it can be removed */
114 ReOpenLog(); /* no trunc, just append */
121 create_cipher(char *cipher
, int *cipherLen
,
122 struct ktc_encryptionKey
*sessionKey
, char *sname
,
123 char *sinst
, Date start
, Date end
, afs_int32 kvno
,
124 char *ticket
, int ticketLen
, struct ktc_encryptionKey
*key
)
128 unsigned char life
= time_to_life(start
, end
);
130 DES_key_schedule schedule
;
135 sizeof(*sessionKey
) + strlen(sname
) + strlen(sinst
) + strlen(lrealm
) +
136 3 /*nulls */ + 3 + ticketLen
+ sizeof(Date
);
137 if (len
> *cipherLen
)
138 return KAANSWERTOOLONG
;
140 return KAANSWERTOOLONG
;
142 return KAANSWERTOOLONG
;
144 memcpy(answer
, sessionKey
, sizeof(*sessionKey
));
145 answer
+= sizeof(*sessionKey
);
150 *answer
++ = (unsigned char)kvno
;
151 *answer
++ = (unsigned char)ticketLen
;
152 memcpy(answer
, ticket
, ticketLen
);
157 printf("Printing ticket (%d) and date: ", ticketLen
);
158 ka_PrintBytes(ticket
, ticketLen
);
159 ka_PrintBytes(answer
- 4, 4);
163 if ((code
= DES_key_sched(ktc_to_cblock(key
), &schedule
)))
164 printf("In KAAuthenticate: key_sched returned %d\n", code
);
165 DES_pcbc_encrypt(cipher
, cipher
, len
, &schedule
, ktc_to_cblockptr(key
), ENCRYPT
);
166 *cipherLen
= round_up_to_ebs(len
);
169 printf("Printing cipher (%d): ", *cipherLen
);
170 ka_PrintBytes(cipher
, *cipherLen
);
177 create_reply(struct packet
*ans
, char *name
, char *inst
, Date startTime
,
178 Date endTime
, afs_int32 kvno
, char *cipher
, int cipherLen
)
180 char *answer
= ans
->data
;
183 ans
->len
= 2 + strlen(name
) + strlen(inst
) + 3 /*nulls */ +
184 sizeof(afs_int32
) + 1 /*ntkts */ + sizeof(afs_int32
) + 1 /*kvno */ +
185 sizeof(short) + cipherLen
;
186 if (ans
->len
> sizeof(ans
->data
))
187 return KAANSWERTOOLONG
;
189 return KAANSWERTOOLONG
;
191 *answer
++ = (unsigned char)KRB_PROT_VERSION
;
192 *answer
++ = (unsigned char)AUTH_MSG_KDC_REPLY
;
193 /* always send claiming network byte order */
198 *answer
++ = 1; /* undocumented number of tickets! */
200 *answer
++ = (unsigned char)kvno
;
202 short w
= (short)cipherLen
;
204 memcpy(answer
, &w
, sizeof(short));
205 answer
+= sizeof(short);
207 memcpy(answer
, cipher
, cipherLen
);
212 check_auth(struct packet
*pkt
, char *auth
, int authLen
,
213 struct ktc_encryptionKey
*key
, char *name
, char *inst
,
217 DES_key_schedule schedule
;
220 int byteOrder
= pkt
->byteOrder
;
222 DES_key_sched(ktc_to_cblock(key
), &schedule
);
223 DES_pcbc_encrypt(auth
, auth
, authLen
, &schedule
, ktc_to_cblockptr(key
), DECRYPT
);
225 if (strcmp(packet
, name
) != 0)
227 packet
+= strlen(packet
) + 1;
228 if (strcmp(packet
, inst
) != 0)
230 packet
+= strlen(packet
) + 1;
231 if (strcmp(packet
, cell
) != 0)
233 packet
+= strlen(packet
) + 1;
235 /* Comments in the original IBM source suggest this byte was/is "time_msec" */
238 if ((packet
- auth
) > authLen
)
244 UDP_Authenticate(int ksoc
, struct sockaddr_in
*client
, char *name
,
245 char *inst
, Date startTime
, Date endTime
, char *sname
,
248 struct ubik_trans
*tt
;
249 afs_int32 to
; /* offset of block */
250 struct kaentry tentry
;
251 afs_int32 tgskvno
; /* key version of service key */
252 struct ktc_encryptionKey tgskey
; /* service key for encrypting ticket */
257 char ticket
[MAXKTCTICKETLEN
]; /* our copy of the ticket */
259 struct ktc_encryptionKey sessionKey
; /* we have to invent a session key */
261 char cipher
[2 * MAXKTCTICKETLEN
]; /* put encrypted part of answer here */
265 COUNT_REQ(UAuthenticate
);
266 if (!name_instance_legal(name
, inst
))
267 return KERB_ERR_NAME_EXP
; /* KABADNAME */
268 if ((code
= InitAuthServ(&tt
, LOCKREAD
, this_op
)))
271 code
= FindBlock(tt
, name
, inst
, &to
, &tentry
);
274 if (to
) { /* if user exists check other stuff */
276 struct kaentry sentry
;
278 unsigned char misc_auth_bytes
[4];
279 afs_uint32 temp
; /* unsigned for safety */
280 afs_uint32 pwexpires
;
282 save_principal(udpAuthPrincipal
, name
, inst
, 0);
284 tgt
= ((strcmp(sname
, KA_TGS_NAME
) == 0)
285 && (strcmp(sinst
, lrealm
) == 0));
286 if ((ntohl(tentry
.user_expiration
) < now
)
287 || (tgt
&& (ntohl(tentry
.flags
) & KAFNOTGS
))) {
288 code
= KERB_ERR_NAME_EXP
; /* KABADUSER */
291 code
= FindBlock(tt
, KA_TGS_NAME
, lrealm
, &sto
, &sentry
);
298 if ((ntohl(sentry
.user_expiration
) < now
)) {
299 code
= KERB_ERR_NAME_EXP
; /* XXX Could use another error code XXX */
302 if (check_ka_skew(startTime
, now
, KTC_TIME_UNCERTAINTY
)) {
303 code
= KERB_ERR_SERVICE_EXP
; /* was KABADREQUEST */
307 memcpy(&temp
, tentry
.misc_auth_bytes
, sizeof(afs_uint32
));
309 unpack_long(temp
, misc_auth_bytes
);
310 pwexpires
= misc_auth_bytes
[0];
313 ntohl(tentry
.change_password_time
) +
314 24 * 60 * 60 * pwexpires
;
315 if (pwexpires
< now
) {
316 code
= KERB_ERR_AUTH_EXP
; /* was KAPWEXPIRED */
321 /* make the ticket */
322 code
= DES_new_random_key(ktc_to_cblock(&sessionKey
));
324 code
= KERB_ERR_NULL_KEY
; /* was KANOKEYS */
328 umin(endTime
, startTime
+ ntohl(tentry
.max_ticket_lifetime
));
329 if ((code
= ka_LookupKey(tt
, sname
, sinst
, &tgskvno
, &tgskey
))
331 tkt_MakeTicket(ticket
, &ticketLen
, &tgskey
, name
, inst
,
332 lrealm
, startTime
, endTime
, &sessionKey
,
333 htonl(client
->sin_addr
.s_addr
), sname
, sinst
)))
336 cipherLen
= sizeof(cipher
);
338 create_cipher(cipher
, &cipherLen
, &sessionKey
, sname
, sinst
,
339 startTime
, endTime
, tgskvno
, ticket
, ticketLen
,
343 } else { /* no such user */
345 tentry
.key_version
= 0;
347 code
= ubik_EndTrans(tt
);
352 create_reply(&ans
, name
, inst
, startTime
, endTime
,
353 ntohl(tentry
.key_version
), cipher
, cipherLen
);
358 printf("Sending %d bytes ending in: ", ans
.len
);
359 ka_PrintBytes(ans
.data
+ ans
.len
- 8, 8);
364 sendto(ksoc
, ans
.data
, ans
.len
, 0, (struct sockaddr
*)client
,
366 if (code
!= ans
.len
) {
367 perror("calling sendto");
371 KALOG(name
, inst
, sname
, sinst
, NULL
, client
->sin_addr
.s_addr
,
374 if (cipherLen
!= 0) {
375 KALOG(name
, inst
, sname
, sinst
, NULL
, client
->sin_addr
.s_addr
,
378 osi_audit(UDPAuthenticateEvent
, 0, AUD_STR
, name
, AUD_STR
, inst
, AUD_END
);
386 osi_audit(UDPAuthenticateEvent
, code
, AUD_STR
, name
, AUD_STR
, inst
,
392 UDP_GetTicket(int ksoc
, struct packet
*pkt
, afs_int32 kvno
,
393 char *authDomain
, char *ticket
, int ticketLen
, char *auth
,
397 struct ktc_encryptionKey tgskey
;
398 char name
[MAXKTCNAMELEN
];
399 char inst
[MAXKTCNAMELEN
];
400 char cell
[MAXKTCREALMLEN
];
401 struct ktc_encryptionKey authSessionKey
;
411 int byteOrder
= pkt
->byteOrder
;
412 char sname
[MAXKTCNAMELEN
];
413 char sinst
[MAXKTCNAMELEN
];
417 struct ubik_trans
*tt
;
419 struct kaentry caller
;
420 struct kaentry server
;
422 struct ktc_encryptionKey sessionKey
;
424 char newTicket
[MAXKTCTICKETLEN
];
426 char cipher
[2 * MAXKTCTICKETLEN
]; /* put encrypted part of answer here */
430 COUNT_REQ(UGetTicket
);
432 if ((code
= InitAuthServ(&tt
, LOCKREAD
, this_op
)))
435 ka_LookupKvno(tt
, KA_TGS_NAME
,
436 ((strlen(authDomain
) > 0) ? authDomain
: lrealm
), kvno
,
442 tkt_DecodeTicket(ticket
, ticketLen
, &tgskey
, name
, inst
, cell
,
443 &authSessionKey
, &host
, &start
, &authEnd
);
448 code
= KERB_ERR_AUTH_EXP
; /* was KANOAUTH */
451 save_principal(udptgsPrincipal
, name
, inst
, cell
);
452 code
= tkt_CheckTimes(start
, authEnd
, now
);
455 code
= KERB_ERR_SERVICE_EXP
; /* was RXKADEXPIRED */
458 code
= KERB_ERR_AUTH_EXP
; /* was KANOAUTH */
461 celllen
= strlen(cell
);
463 if ((strlen(authDomain
) > 0) && (strcmp(authDomain
, lrealm
) != 0))
465 if (import
&& (celllen
== 0)) {
466 code
= KERB_ERR_PKT_VER
; /* was KABADTICKET */
470 strncpy(cell
, lrealm
, MAXKTCREALMLEN
- 1);
471 cell
[MAXKTCREALMLEN
- 1] = 0;
474 if (!krb4_cross
&& strcmp(lrealm
, cell
) != 0) {
475 code
= KERB_ERR_PRINCIPAL_UNKNOWN
;
480 printf("UGetTicket: got ticket from '%s'.'%s'@'%s'\n", name
, inst
,
484 code
= check_auth(pkt
, auth
, authLen
, &authSessionKey
, name
, inst
, cell
);
488 /* authenticator and all is OK so read actual request */
491 life
= *(unsigned char *)packet
++;
495 reqEnd
= life_to_time(start
, life
);
497 printf("UGetTicket: request for server '%s'.'%s'\n", sname
, sinst
);
499 save_principal(udptgsServerPrincipal
, sname
, sinst
, 0);
502 strcpy(caller
.userID
.name
, name
);
503 strcpy(caller
.userID
.instance
, inst
);
504 caller
.max_ticket_lifetime
= htonl(MAXKTCTICKETLIFETIME
);
506 code
= FindBlock(tt
, name
, inst
, &to
, &caller
);
510 ka_PrintUserID("GetTicket: User ", name
, inst
, " unknown.\n");
511 code
= KERB_ERR_PRINCIPAL_UNKNOWN
; /* KANOENT */
514 if (ntohl(caller
.flags
) & KAFNOTGS
) {
515 code
= KERB_ERR_AUTH_EXP
; /* was KABADUSER */
520 code
= FindBlock(tt
, sname
, sinst
, &to
, &server
); /* get server's entry */
523 if (to
== 0) { /* entry not found */
524 ka_PrintUserID("GetTicket: Server ", sname
, sinst
, " unknown.\n");
525 code
= KERB_ERR_PRINCIPAL_UNKNOWN
; /* KANOENT */
528 code
= ubik_EndTrans(tt
);
532 if (ntohl(server
.flags
) & KAFNOSEAL
)
535 code
= DES_new_random_key(ktc_to_cblock(&sessionKey
));
537 code
= KERB_ERR_NULL_KEY
; /* was KANOKEYS */
542 umin(umin(reqEnd
, authEnd
),
543 umin(start
+ ntohl(caller
.max_ticket_lifetime
),
544 start
+ ntohl(server
.max_ticket_lifetime
)));
547 tkt_MakeTicket(newTicket
, &newTicketLen
, &server
.key
,
548 caller
.userID
.name
, caller
.userID
.instance
, cell
,
549 start
, reqEnd
, &sessionKey
,
550 htonl(pkt
->from
.sin_addr
.s_addr
), server
.userID
.name
,
551 server
.userID
.instance
);
555 cipherLen
= sizeof(cipher
);
557 create_cipher(cipher
, &cipherLen
, &sessionKey
, sname
, sinst
, start
,
558 reqEnd
, ntohl(server
.key_version
), newTicket
,
559 newTicketLen
, &authSessionKey
);
564 create_reply(&ans
, name
, inst
, start
, reqEnd
, 0, cipher
, cipherLen
);
569 sendto(ksoc
, ans
.data
, ans
.len
, 0, (struct sockaddr
*)&pkt
->from
,
571 if (code
!= ans
.len
) {
572 perror("calling sendto");
577 if (cipherLen
!= 0) {
578 KALOG(name
, inst
, sname
, sinst
, NULL
, host
, LOG_GETTICKET
);
580 osi_audit(UDPGetTicketEvent
, 0, AUD_STR
, name
, AUD_STR
, inst
, AUD_STR
,
581 cell
, AUD_STR
, sname
, AUD_STR
, sinst
, AUD_END
);
587 osi_audit(UDPGetTicketEvent
, code
, AUD_STR
, name
, AUD_STR
, inst
, AUD_STR
,
588 NULL
, AUD_STR
, NULL
, AUD_STR
, NULL
, AUD_END
);
593 err_packet(int ksoc
, struct packet
*pkt
, afs_int32 code
, char *reason
)
596 char *answer
= ans
.data
;
602 snprintf(buf
, 255, "code = %d: %s", code
, reason
);
605 printf("Sending error packet to '%s'.'%s'@'%s' containing %s\n",
606 pkt
->name
, pkt
->inst
, pkt
->realm
, buf
);
610 2 + strlen(pkt
->name
) + strlen(pkt
->inst
) + strlen(pkt
->realm
) +
611 3 /* nulls */ + (2 * sizeof(afs_int32
)) + strlen(buf
) + 1;
612 if (ans
.len
> sizeof(ans
.data
)) {
613 printf("Answer packet too long\n");
617 *answer
++ = (unsigned char)KRB_PROT_VERSION
;
618 *answer
++ = (unsigned char)AUTH_MSG_ERR_REPLY
;
619 /* always send claiming network byte order */
624 if ((code
< 0) || (code
> KERB_ERR_MAXIMUM
)) {
625 /* It could be because of kauth errors so we should return something instead of success!! */
632 sendto(ksoc
, ans
.data
, ans
.len
, 0, (struct sockaddr
*)&pkt
->from
,
634 if (code
!= ans
.len
) {
637 ("call to sendto returned %d, sending error packet %d bytes long\n",
640 perror("err_packet: sendto");
646 process_udp_auth(int ksoc
, struct packet
*pkt
)
648 char *packet
= pkt
->rest
;
649 char name
[MAXKTCNAMELEN
];
650 char inst
[MAXKTCNAMELEN
];
651 char realm
[MAXKTCREALMLEN
];
652 char sname
[MAXKTCNAMELEN
];
653 char sinst
[MAXKTCNAMELEN
];
656 Date startTime
, endTime
;
657 unsigned char lifetime
;
667 printf("Processing KDC Request from '%s'.'%s'@'%s'\n", name
, inst
,
671 if ((strlen(realm
) > 0) && (strcmp(realm
, lrealm
) != 0)) {
672 err_packet(ksoc
, pkt
, KERB_ERR_NONNULL_REALM
,
673 "null realm name not allowed");
676 memcpy(&startTime
, packet
, sizeof(startTime
));
677 packet
+= sizeof(startTime
);
678 startTime
= ktohl(pkt
->byteOrder
, startTime
);
679 pkt
->time
= startTime
;
680 lifetime
= *packet
++;
681 endTime
= life_to_time(startTime
, lifetime
);
682 code
= tkt_CheckTimes(startTime
, endTime
, now
);
684 err_packet(ksoc
, pkt
, KERB_ERR_BAD_LIFETIME
,
685 "requested ticket lifetime invalid");
690 if ((packet
- pkt
->data
) != pkt
->len
) {
691 err_packet(ksoc
, pkt
, KERB_ERR_PKT_LENGTH
,
692 "packet length inconsistent");
697 UDP_Authenticate(ksoc
, &pkt
->from
, name
, inst
, startTime
, endTime
,
700 if (code
== KANOENT
) {
701 code
= KERB_ERR_PRINCIPAL_UNKNOWN
;
702 err_packet(ksoc
, pkt
, code
, (char *)afs_error_message(code
));
703 } else if (code
== KAPWEXPIRED
) {
704 code
= KERB_ERR_NAME_EXP
;
705 err_packet(ksoc
, pkt
, code
, "password has expired");
707 err_packet(ksoc
, pkt
, code
, (char *)afs_error_message(code
));
713 process_udp_appl(int ksoc
, struct packet
*pkt
)
715 char *packet
= pkt
->rest
;
717 char realm
[MAXKTCREALMLEN
];
718 char ticket
[MAXKTCTICKETLEN
];
719 char auth
[3 * MAXKTCNAMELEN
+ 4 + 5];
721 int ticketLen
, authLen
;
725 printf("Processing APPL Request\n");
729 ticketLen
= *(unsigned char *)packet
++;
730 authLen
= *(unsigned char *)packet
++;
731 if (ticketLen
> sizeof(ticket
)) {
732 err_packet(ksoc
, pkt
, KERB_ERR_TEXT_LENGTH
, "ticket too long");
735 memcpy(ticket
, packet
, ticketLen
);
737 if (authLen
> sizeof(auth
)) {
738 err_packet(ksoc
, pkt
, KERB_ERR_TEXT_LENGTH
, "authenticator too long");
741 memcpy(auth
, packet
, authLen
);
742 pkt
->rest
= packet
+ authLen
;
744 UDP_GetTicket(ksoc
, pkt
, kvno
, realm
, ticket
, ticketLen
, auth
,
748 code
= KERB_ERR_PRINCIPAL_UNKNOWN
;
749 err_packet(ksoc
, pkt
, code
, (char *)afs_error_message(code
));
756 process_udp_request(int ksoc
, struct packet
*pkt
)
758 char *packet
= pkt
->data
;
759 unsigned char version
, auth_msg_type
;
762 if (version
!= KRB_PROT_VERSION
) {
763 err_packet(ksoc
, pkt
, KERB_ERR_PKT_VER
,
764 "packet version number unknown");
767 auth_msg_type
= *packet
++;
768 pkt
->byteOrder
= auth_msg_type
& 1;
770 switch (auth_msg_type
& ~1) {
771 case AUTH_MSG_KDC_REQUEST
:
772 process_udp_auth(ksoc
, pkt
);
774 case AUTH_MSG_APPL_REQUEST
:
775 process_udp_appl(ksoc
, pkt
);
778 printf("unknown msg type 0x%x\n", auth_msg_type
);
779 err_packet(ksoc
, pkt
, KERB_ERR_BAD_MSG_TYPE
,
780 "message type not supported");
787 SocketListener(void *unused
)
791 struct packet packet
;
796 printf("Starting to listen for UDP packets\n");
800 FD_SET(sock_kerb
, &rfds
);
802 FD_SET(sock_kerb5
, &rfds
);
806 /* write and exception fd_set's are null */
807 code
= IOMGR_Select(32, &rfds
, NULL
, NULL
, &tv
);
808 if (code
== 0) { /* timeout */
809 /* printf ("Timeout\n"); */
811 } else if (code
< 0) {
812 perror("calling IOMGR_Select");
816 fromLen
= sizeof(packet
.from
);
817 if ((sock_kerb
>= 0) && FD_ISSET(sock_kerb
, &rfds
)) {
819 recvfrom(sock_kerb
, packet
.data
, sizeof(packet
.data
), 0,
820 (struct sockaddr
*)&packet
.from
, &fromLen
);
822 if (errno
== EAGAIN
|| errno
== ECONNREFUSED
)
824 perror("calling recvfrom");
829 printf("Kerb:udp: Got %d bytes from addr %s which are '",
830 code
, afs_inet_ntoa_r(packet
.from
.sin_addr
.s_addr
, hoststr
));
831 ka_PrintBytes(packet
.data
, packet
.len
);
834 packet
.name
= packet
.inst
= packet
.realm
= "";
836 process_udp_request(sock_kerb
, &packet
);
839 if ((sock_kerb5
>= 0) && FD_ISSET(sock_kerb5
, &rfds
)) {
841 recvfrom(sock_kerb5
, packet
.data
, sizeof(packet
.data
), 0,
842 (struct sockaddr
*)&packet
.from
, &fromLen
);
844 if (errno
== EAGAIN
|| errno
== ECONNREFUSED
)
846 perror("calling recvfrom");
851 printf("Kerb5:udp: Got %d bytes from addr %s which are '",
852 code
, afs_inet_ntoa_r(packet
.from
.sin_addr
.s_addr
, hoststr
));
853 ka_PrintBytes(packet
.data
, packet
.len
);
856 packet
.name
= packet
.inst
= packet
.realm
= "";
858 process_udp_request(sock_kerb5
, &packet
);
861 if (sock_kerb
>= 0) {
862 closesocket(sock_kerb
);
865 if (sock_kerb5
>= 0) {
866 closesocket(sock_kerb5
);
869 printf("UDP SocketListener exiting due to error\n");
876 #include "AFS_component_version_number.c"
885 struct sockaddr_in taddr
;
886 static PROCESS slPid
; /* socket listener pid */
887 static PROCESS checkPid
; /* fiveminute check */
889 char *krb4name
; /* kerberos version4 service */
895 static int inited
= 0;
902 memset(&taddr
, 0, sizeof(taddr
));
903 krb4name
= "kerberos4";
904 sp
= getservbyname(krb4name
, "udp");
905 taddr
.sin_family
= AF_INET
; /* added for NCR port */
906 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
907 taddr
.sin_len
= sizeof(struct sockaddr_in
);
910 /* if kerberos-4 is not available, try "kerberos-iv" */
911 krb4name
= "kerberos-iv";
912 sp
= getservbyname(krb4name
, "udp");
915 /* if kerberos-iv is not available, try "kerberos" */
916 krb4name
= "kerberos";
917 sp
= getservbyname(krb4name
, "udp");
921 "kerberos/udp is unknown; check /etc/services. Using port=%d as default\n",
923 taddr
.sin_port
= htons(KRB_PORT
);
925 /* copy the port number */
926 fprintf(stderr
, "%s/udp port=%hu\n", krb4name
,
927 (unsigned short)sp
->s_port
);
928 taddr
.sin_port
= sp
->s_port
;
930 kerb_port
= taddr
.sin_port
;
931 sock_kerb
= socket(AF_INET
, SOCK_DGRAM
, 0);
932 code
= bind(sock_kerb
, (struct sockaddr
*)&taddr
, sizeof(taddr
));
934 perror("calling bind");
938 sp
= getservbyname("kerberos5", "udp");
941 "kerberos5/udp is unknown; check /etc/services. Using port=%d as default\n",
943 taddr
.sin_port
= htons(KRB5_PORT
);
945 /* copy the port number */
946 fprintf(stderr
, "kerberos5/udp port=%hu\n",
947 (unsigned short)sp
->s_port
);
948 taddr
.sin_port
= sp
->s_port
;
950 if (taddr
.sin_port
!= kerb_port
) { /* a different port */
951 sock_kerb5
= socket(AF_INET
, SOCK_DGRAM
, 0);
952 code
= bind(sock_kerb5
, (struct sockaddr
*)&taddr
, sizeof(taddr
));
954 perror("calling bind");
959 /* Bail out if we can't bind with any port */
960 if ((sock_kerb
< 0) && (sock_kerb5
< 0))
964 /* this has already been done */
965 LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY
, &junk
);
968 LWP_CreateProcess(SocketListener
, /*stacksize */ 16000,
969 LWP_NORMAL_PRIORITY
, (void *)0, "Socket Listener",
972 /* just to close the log every five minutes */
974 LWP_CreateProcess(FiveMinuteCheckLWP
, 24 * 1024, LWP_MAX_PRIORITY
- 2,
975 (void *)&fiveminutes
, "FiveMinuteChecks", &checkPid
);
978 initialize_ka_error_table();
979 initialize_rxk_error_table();
980 while (1) /* don't just stand there, run it */
989 char *lastOperation
; /* name of last operation */
990 char *lrealm
= "REALMNAME";
991 struct kadstats dynamic_statistics
;
994 InitAuthServ(tt
, lock
, this_op
)
995 struct ubik_trans
**tt
;
996 int lock
; /* read or write transaction */
997 int *this_op
; /* op of RCP routine, for COUNT_ABO */
1002 printf("Calling InitAuthServ\n");
1008 struct ubik_trans
*tt
;
1010 printf("Calling ubik_EndTrans\n");
1016 struct ubik_trans
*tt
;
1018 printf("Calling ubik_AbortTrans\n");
1023 FindBlock(at
, aname
, ainstance
, tentry
)
1024 struct ubik_trans
*at
;
1027 struct kaentry
*tentry
;
1029 printf("Calling FindBlock with '%s'.'%s'\n", aname
, ainstance
);
1030 strcpy(tentry
->userID
.name
, aname
);
1031 strcpy(tentry
->userID
.instance
, ainstance
);
1032 tentry
->key_version
= htonl(17);
1033 DES_string_to_key("toa", &tentry
->key
);
1034 tentry
->flags
= htonl(KAFNORMAL
);
1035 tentry
->user_expiration
= htonl(NEVERDATE
);
1036 tentry
->max_ticket_lifetime
= htonl(MAXKTCTICKETLIFETIME
);
1041 ka_LookupKey(tt
, name
, inst
, kvno
, key
)
1042 struct ubik_trans
*tt
;
1045 afs_int32
*kvno
; /* returned */
1046 struct ktc_encryptionKey
*key
; /* copied out */
1048 printf("Calling ka_LookupKey with '%s'.'%s'\n", name
, inst
);
1050 DES_string_to_key("applexx", key
);
1054 kvno_tgs_key(authDomain
, kvno
, tgskey
)
1057 struct ktc_encryptionKey
*tgskey
;
1059 if (strcmp(authDomain
, lrealm
) != 0)
1060 printf("Called with wrong %s as authDomain\n", authDomain
);
1062 printf("kvno_tgs_key: being called with wrong kvno: %d\n", kvno
);
1063 DES_string_to_key("applexx", tgskey
);
1071 name_instance_legal()