Example of programmatically using session-state?

Arran Cudbard-Bell a.cudbardb at freeradius.org
Wed Sep 9 11:07:03 CEST 2015


> On 9 Sep 2015, at 06:34, Richard Levenberg <richardl at ufp.com> wrote:
> 
> I have been looking at source code to try and figure out how to use
> session-state programmatically from a module. I see that
> src/main/radiusd.c allocates a state using fr_state_init but I don't see
> how to get at that?
> 
> I see in the REQUEST there is a VALUE_PAIR that is a *state, but the
> session-state stuff looks like its from src/main/state.c and I would be
> looking for a state_entry_t or a state_t.
> 
> So are there any examples of using session-state programmatically?


The Session-State list is identical to any other VALUE_PAIR list, it's just managed by the server core, and is transferred between requests linked by the 'State' RADIUS attribute.

You don't need to know about how it works to use it, just modify its contents during the lifetime of the request and the changes will be present in the next REQUEST * in the sequence.

-Arran

VALUE_PAIR *vp;
vp_cursor_t cursor;


for (vp = fr_cursor_init(&cursor, &request->state);
     vp;
     vp = fr_cursor_next(&cursor)) {
	<do stuff>
}



VALUE_PAIR *vp;
vp_cursor_t cursor;

MEM(vp = fr_pair_afrom_num(request, <attr num>, 0));
if (fr_pair_value_from_str(vp, "my_first_value", sizeof("my_first_value") - 1) < 0) {
	ERROR("Failed creating attribute value");
	talloc_free(vp);
	return;
}

fr_cursor_init(&cursor, &request->state)
fr_cursor_insert(&cursor, vp);


See http://doc.freeradius.org for descriptions of the functions.

Arran Cudbard-Bell <a.cudbardb at freeradius.org>
FreeRADIUS development team

FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 872 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freeradius.org/pipermail/freeradius-devel/attachments/20150909/f052e7ab/attachment.sig>


More information about the Freeradius-Devel mailing list