usage of "FR_TOKEN op" parameter to pairmake ?
Hello, I'm trying to figure out the purpose of the last parameter to pairmake (FR_TOKEN op). I assumed it was semantically equivalent to the following unlang syntax : Operators The operator used to assign the value of the attribute may be one of the following, with the given meaning. = Add the attribute to the list, if and only if an attribute of the same name is not already present in that list. := Add the attribute to the list. If any attribute of the same name is already present in that list, its value is replaced with the value of the current attribute. += Add the attribute to the tail of the list, even if attributes of the same name are already present in the list. But, whatever the operator I'm using (T_OP_EQ, T_OP_ADD or T_OP_SET), it doesn't seem to have any effect. All attributes added through pairmake to the reply vp list are returned to the client anyway. (I'm using FreeRADIUS 3.0.1) Did I miss something ? Thanks, Nicolas. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Chaigneau, Nicolas wrote:
I'm trying to figure out the purpose of the last parameter to pairmake (FR_TOKEN op).
The operator is used in many configuration files. So... there needs to be a way to create / use it.
I assumed it was semantically equivalent to the following unlang syntax :
Yes.
But, whatever the operator I'm using (T_OP_EQ, T_OP_ADD or T_OP_SET), it doesn't seem to have any effect. All attributes added through pairmake to the reply vp list are returned to the client anyway.
Yes, because you're manually appending them to the list. If you call pairmove(), it uses the operators to move one list to another. Alan DeKok.
De : Alan DeKok
Chaigneau, Nicolas wrote:
I'm trying to figure out the purpose of the last parameter to pairmake (FR_TOKEN op).
The operator is used in many configuration files. So... there needs to be a way to create / use it.
I assumed it was semantically equivalent to the following unlang syntax :
Yes.
But, whatever the operator I'm using (T_OP_EQ, T_OP_ADD or T_OP_SET), it doesn't seem to have any effect. All attributes added through pairmake to the reply vp list are returned to the client anyway.
Yes, because you're manually appending them to the list.
If you call pairmove(), it uses the operators to move one list to another.
Thanks. So I tried using "pairmove". But I'm encountering some strange behaviour when combining the operators. I don't know if it's a weird bug or I'm doing it wrong (probably the latter...) What I'm doing: // macro for easier use: #define pairmove_reply(_vp, _a, _b, _c) _vp = pairmake(request->reply, NULL, _a, _b, _c); pairmove(request->reply, &(request->reply->vps), &_vp); pairfree(&_vp); VALUE_PAIR *vp_test; pairmove_reply(vp_test, "Reply-Message", "Msg1.EQ", T_OP_EQ); pairmove_reply(vp_test, "Reply-Message", "Msg2.EQ", T_OP_EQ); pairmove_reply(vp_test, "Reply-Message", "Msg3.SET", T_OP_SET); pairmove_reply(vp_test, "Reply-Message", "Msg4.ADD", T_OP_ADD); pairmove_reply(vp_test, "Reply-Message", "Msg5.ADD", T_OP_ADD); At the end I expect to obtain three Reply-Message attributes with, respectively: "Msg3.SET", "Msg4.ADD", "Msg5.ADD". What I get is: rad_recv: Access-Accept packet from host <...> port 1812, id=128, length=143 Reply-Message = 'Msg4.ADD' Reply-Message = 'Msg4.ADD' Reply-Message = 'Msg5.ADD' (ie, twice "Msg4.ADD"). I tried to use "radius_pairmove" instead. I'm not having the same issue with this function. Am I doing something wrong with "pairmove" ? Thanks, Nicolas. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Chaigneau, Nicolas wrote:
So I tried using "pairmove". But I'm encountering some strange behaviour when combining the operators.
The behavior of the operators is documented.
I don't know if it's a weird bug or I'm doing it wrong (probably the latter...)
What I'm doing:
// macro for easier use: #define pairmove_reply(_vp, _a, _b, _c) _vp = pairmake(request->reply, NULL, _a, _b, _c); pairmove(request->reply, &(request->reply->vps), &_vp); pairfree(&_vp);
That marco is not recommended. You don't check that _vp is NULL. Also, the second argument to pairmake() is NULL. Why? It should be the destination list. So there's no need to call pairmove() *after* calling pairmake(). You should just call pairmake() with a pointer to the list.
VALUE_PAIR *vp_test;
pairmove_reply(vp_test, "Reply-Message", "Msg1.EQ", T_OP_EQ); pairmove_reply(vp_test, "Reply-Message", "Msg2.EQ", T_OP_EQ); pairmove_reply(vp_test, "Reply-Message", "Msg3.SET", T_OP_SET); pairmove_reply(vp_test, "Reply-Message", "Msg4.ADD", T_OP_ADD); pairmove_reply(vp_test, "Reply-Message", "Msg5.ADD", T_OP_ADD);
At the end I expect to obtain three Reply-Message attributes with, respectively: "Msg3.SET", "Msg4.ADD", "Msg5.ADD". What I get is:
rad_recv: Access-Accept packet from host <...> port 1812, id=128, length=143 Reply-Message = 'Msg4.ADD' Reply-Message = 'Msg4.ADD' Reply-Message = 'Msg5.ADD'
(ie, twice "Msg4.ADD").
That does appear wrong.
I tried to use "radius_pairmove" instead. I'm not having the same issue with this function.
Well... that would suggest it's the better function to use.
Am I doing something wrong with "pairmove" ?
Maybe, maybe not. But your use of the functions / macro above is weird. Alan DeKok.
On 4 Feb 2014, at 08:53, Chaigneau, Nicolas <nicolas.chaigneau@capgemini.com> wrote:
De : Alan DeKok
Chaigneau, Nicolas wrote:
I'm trying to figure out the purpose of the last parameter to pairmake (FR_TOKEN op).
The operator is used in many configuration files. So... there needs to be a way to create / use it.
I assumed it was semantically equivalent to the following unlang syntax :
Yes.
But, whatever the operator I'm using (T_OP_EQ, T_OP_ADD or T_OP_SET), it doesn't seem to have any effect. All attributes added through pairmake to the reply vp list are returned to the client anyway.
Yes, because you're manually appending them to the list.
If you call pairmove(), it uses the operators to move one list to another.
Thanks.
So I tried using "pairmove". But I'm encountering some strange behaviour when combining the operators. I don't know if it's a weird bug or I'm doing it wrong (probably the latter...)
What I'm doing:
// macro for easier use: #define pairmove_reply(_vp, _a, _b, _c) _vp = pairmake(request->reply, NULL, _a, _b, _c); pairmove(request->reply, &(request->reply->vps), &_vp); pairfree(&_vp);
Your macro is wrong it should be #define pairmove_reply(_vp, _a, _b, _c) do {\ _vp = pairmake(request, NULL, _a, _b, _c);\ pairmove(request, &(request->reply->vps), &_vp); \ pairfree(&_vp); \ while (0) I'll look at it properly later... Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS Development Team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
Your macro is wrong it should be
#define pairmove_reply(_vp, _a, _b, _c) do {\ _vp = pairmake(request, NULL, _a, _b, _c);\ pairmove(request, &(request->reply->vps), &_vp); \ pairfree(&_vp); \ while (0)
And Alan says, passing NULL to pairmake and then calling pairmove is weird, even though pairmake will do the right thing in this case. Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS Development Team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
Chaigneau, Nicolas wrote:
So I tried using "pairmove". But I'm encountering some strange behaviour when combining the operators. I don't know if it's a weird bug or I'm doing it wrong (probably the latter...)
I've taken a look at pairmove(). It was a bug. I've pushed a fix. Alan DeKok.
participants (3)
-
Alan DeKok -
Arran Cudbard-Bell -
Chaigneau, Nicolas