Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_radius_pdu.c File Reference
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "gwlib/gwlib.h"
#include "radius/radius_pdu.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file test_radius_pdu.c.

References debug(), error(), filename, get_and_set_debugs(), gwlib_init(), gwlib_shutdown(), octstr_create, octstr_destroy(), octstr_dump_short(), octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_read_file(), radius_authenticate_pdu(), radius_pdu_create(), radius_pdu_destroy(), radius_pdu_pack(), radius_pdu_unpack(), and RADIUS_PDU::u.

71 {
72  Octstr *data, *filename, *rdata;
73  RADIUS_PDU *pdu, *r;
74 
75  gwlib_init();
76 
77  data = filename = rdata = NULL;
78  get_and_set_debugs(argc, argv, NULL);
79 
80  if (argc <= 1) {
81  debug("",0,"Usage: %s [filename containing raw RADIUS PDU]", argv[0]);
82  goto error;
83  }
84 
85  filename = octstr_create(argv[1]);
86  if ((data = octstr_read_file(octstr_get_cstr(filename))) == NULL)
87  goto error;
88 
89  debug("",0,"Calling radius_pdu_unpack() now");
90  pdu = radius_pdu_unpack(data);
91 
92  debug("",0,"PDU type code: %ld", pdu->u.Accounting_Request.code);
93  debug("",0,"PDU identifier: %ld", pdu->u.Accounting_Request.identifier);
94  debug("",0,"PDU length: %ld", pdu->u.Accounting_Request.length);
95  octstr_dump_short(pdu->u.Accounting_Request.authenticator,0, "PDU authenticator");
96 
97  /* XXX authenticator md5 check does not work?! */
98  /* radius_authenticate_pdu(pdu, data, octstr_imm("radius")); */
99 
100  /* create response PDU */
101  r = radius_pdu_create(0x05, pdu);
102 
103  /* create response authenticator
104  * code+identifier(req)+length+authenticator(req)+(attributes)+secret
105  */
106  r->u.Accounting_Response.identifier = pdu->u.Accounting_Request.identifier;
107  r->u.Accounting_Response.authenticator = octstr_duplicate(pdu->u.Accounting_Request.authenticator);
108 
109  rdata = radius_pdu_pack(r);
110 
111  /* creates response autenticator in encoded PDU */
112  radius_authenticate_pdu(r, &rdata, octstr_imm("radius"));
113 
114  octstr_dump_short(rdata, 0, "Encoded Response PDU");
115 
116  debug("",0,"Destroying RADIUS_PDUs");
117  radius_pdu_destroy(pdu);
119 
120 error:
121  octstr_destroy(data);
122  octstr_destroy(rdata);
123  octstr_destroy(filename);
124 
125  gwlib_shutdown();
126 
127  return 0;
128 }
void error(int err, const char *fmt,...)
Definition: log.c:612
RADIUS_PDU * radius_pdu_unpack(Octstr *data_without_len)
Definition: radius_pdu.c:360
union RADIUS_PDU::@72 u
void octstr_dump_short(Octstr *ostr, int level, const char *name)
Definition: octstr.c:2142
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void radius_pdu_destroy(RADIUS_PDU *pdu)
Definition: radius_pdu.c:156
int radius_authenticate_pdu(RADIUS_PDU *pdu, Octstr **data, Octstr *secret)
Definition: radius_pdu.c:416
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
char filename[FILENAME_MAX+1]
Definition: log.c:135
#define octstr_create(cstr)
Definition: octstr.h:125
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1546
RADIUS_PDU * radius_pdu_create(int type, RADIUS_PDU *req)
Definition: radius_pdu.c:123
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void gwlib_shutdown(void)
Definition: gwlib.c:94
Octstr * radius_pdu_pack(RADIUS_PDU *pdu)
Definition: radius_pdu.c:237
void gwlib_init(void)
Definition: gwlib.c:78
int get_and_set_debugs(int argc, char **argv, int(*find_own)(int index, int argc, char **argv))
Definition: utils.c:626
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.