xref: /freebsd/crypto/krb5/src/lib/krad/code.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /* lib/krad/code.c - RADIUS code name table for libkrad */
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert  * Copyright 2013 Red Hat, Inc.  All rights reserved.
5*7f2fe78bSCy Schubert  *
6*7f2fe78bSCy Schubert  * Redistribution and use in source and binary forms, with or without
7*7f2fe78bSCy Schubert  * modification, are permitted provided that the following conditions are met:
8*7f2fe78bSCy Schubert  *
9*7f2fe78bSCy Schubert  *    1. Redistributions of source code must retain the above copyright
10*7f2fe78bSCy Schubert  *       notice, this list of conditions and the following disclaimer.
11*7f2fe78bSCy Schubert  *
12*7f2fe78bSCy Schubert  *    2. Redistributions in binary form must reproduce the above copyright
13*7f2fe78bSCy Schubert  *       notice, this list of conditions and the following disclaimer in
14*7f2fe78bSCy Schubert  *       the documentation and/or other materials provided with the
15*7f2fe78bSCy Schubert  *       distribution.
16*7f2fe78bSCy Schubert  *
17*7f2fe78bSCy Schubert  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18*7f2fe78bSCy Schubert  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19*7f2fe78bSCy Schubert  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20*7f2fe78bSCy Schubert  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21*7f2fe78bSCy Schubert  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22*7f2fe78bSCy Schubert  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23*7f2fe78bSCy Schubert  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24*7f2fe78bSCy Schubert  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25*7f2fe78bSCy Schubert  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26*7f2fe78bSCy Schubert  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27*7f2fe78bSCy Schubert  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*7f2fe78bSCy Schubert  */
29*7f2fe78bSCy Schubert 
30*7f2fe78bSCy Schubert #include "internal.h"
31*7f2fe78bSCy Schubert 
32*7f2fe78bSCy Schubert #include <string.h>
33*7f2fe78bSCy Schubert 
34*7f2fe78bSCy Schubert static const char *codes[UCHAR_MAX] = {
35*7f2fe78bSCy Schubert     "Access-Request",
36*7f2fe78bSCy Schubert     "Access-Accept",
37*7f2fe78bSCy Schubert     "Access-Reject",
38*7f2fe78bSCy Schubert     "Accounting-Request",
39*7f2fe78bSCy Schubert     "Accounting-Response",
40*7f2fe78bSCy Schubert     "Accounting-Status",
41*7f2fe78bSCy Schubert     "Password-Request",
42*7f2fe78bSCy Schubert     "Password-Ack",
43*7f2fe78bSCy Schubert     "Password-Reject",
44*7f2fe78bSCy Schubert     "Accounting-Message",
45*7f2fe78bSCy Schubert     "Access-Challenge",
46*7f2fe78bSCy Schubert     "Status-Server",
47*7f2fe78bSCy Schubert     "Status-Client",
48*7f2fe78bSCy Schubert     NULL,
49*7f2fe78bSCy Schubert     NULL,
50*7f2fe78bSCy Schubert     NULL,
51*7f2fe78bSCy Schubert     NULL,
52*7f2fe78bSCy Schubert     NULL,
53*7f2fe78bSCy Schubert     NULL,
54*7f2fe78bSCy Schubert     NULL,
55*7f2fe78bSCy Schubert     "Resource-Free-Request",
56*7f2fe78bSCy Schubert     "Resource-Free-Response",
57*7f2fe78bSCy Schubert     "Resource-Query-Request",
58*7f2fe78bSCy Schubert     "Resource-Query-Response",
59*7f2fe78bSCy Schubert     "Alternate-Resource-Reclaim-Request",
60*7f2fe78bSCy Schubert     "NAS-Reboot-Request",
61*7f2fe78bSCy Schubert     "NAS-Reboot-Response",
62*7f2fe78bSCy Schubert     NULL,
63*7f2fe78bSCy Schubert     "Next-Passcode",
64*7f2fe78bSCy Schubert     "New-Pin",
65*7f2fe78bSCy Schubert     "Terminate-Session",
66*7f2fe78bSCy Schubert     "Password-Expired",
67*7f2fe78bSCy Schubert     "Event-Request",
68*7f2fe78bSCy Schubert     "Event-Response",
69*7f2fe78bSCy Schubert     NULL,
70*7f2fe78bSCy Schubert     NULL,
71*7f2fe78bSCy Schubert     NULL,
72*7f2fe78bSCy Schubert     NULL,
73*7f2fe78bSCy Schubert     NULL,
74*7f2fe78bSCy Schubert     "Disconnect-Request",
75*7f2fe78bSCy Schubert     "Disconnect-Ack",
76*7f2fe78bSCy Schubert     "Disconnect-Nak",
77*7f2fe78bSCy Schubert     "Change-Filters-Request",
78*7f2fe78bSCy Schubert     "Change-Filters-Ack",
79*7f2fe78bSCy Schubert     "Change-Filters-Nak",
80*7f2fe78bSCy Schubert     NULL,
81*7f2fe78bSCy Schubert     NULL,
82*7f2fe78bSCy Schubert     NULL,
83*7f2fe78bSCy Schubert     NULL,
84*7f2fe78bSCy Schubert     "IP-Address-Allocate",
85*7f2fe78bSCy Schubert     "IP-Address-Release",
86*7f2fe78bSCy Schubert };
87*7f2fe78bSCy Schubert 
88*7f2fe78bSCy Schubert krad_code
krad_code_name2num(const char * name)89*7f2fe78bSCy Schubert krad_code_name2num(const char *name)
90*7f2fe78bSCy Schubert {
91*7f2fe78bSCy Schubert     unsigned char i;
92*7f2fe78bSCy Schubert 
93*7f2fe78bSCy Schubert     for (i = 0; i < UCHAR_MAX; i++) {
94*7f2fe78bSCy Schubert         if (codes[i] == NULL)
95*7f2fe78bSCy Schubert             continue;
96*7f2fe78bSCy Schubert 
97*7f2fe78bSCy Schubert         if (strcmp(codes[i], name) == 0)
98*7f2fe78bSCy Schubert             return ++i;
99*7f2fe78bSCy Schubert     }
100*7f2fe78bSCy Schubert 
101*7f2fe78bSCy Schubert     return 0;
102*7f2fe78bSCy Schubert }
103*7f2fe78bSCy Schubert 
104*7f2fe78bSCy Schubert const char *
krad_code_num2name(krad_code code)105*7f2fe78bSCy Schubert krad_code_num2name(krad_code code)
106*7f2fe78bSCy Schubert {
107*7f2fe78bSCy Schubert     if (code == 0)
108*7f2fe78bSCy Schubert         return NULL;
109*7f2fe78bSCy Schubert 
110*7f2fe78bSCy Schubert     return codes[code - 1];
111*7f2fe78bSCy Schubert }
112