1
/* attrib.c - Procedures for handling internal list of attributes
2
* for accounting and authorization functions.
4
* Copyright (C) 2010, Pawel Krawczyk <pawel.krawczyk@hush.com> and
5
* Jeroen Nijhof <jeroen@nijhofnet.nl>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program - see the file COPYING.
20
* See `CHANGES' file for revision history.
27
void tac_add_attrib(struct tac_attrib **attr, char *name, char *value) {
28
tac_add_attrib_pair(attr, name, '=', value);
31
void tac_add_attrib_pair(struct tac_attrib **attr, char *name, char sep, char *value) {
33
u_char l1 = (u_char) strlen(name);
34
u_char l2 = (u_char) strlen(value);
35
int total_len = l1 + l2 + 1; /* "name" + "=" + "value" */
37
if (total_len > 255) {
38
TACSYSLOG((LOG_WARNING,\
39
"%s: attribute `%s' total length exceeds 255 characters, skipping",\
44
/* initialize the list if application passed us a null pointer */
46
*attr = (struct tac_attrib *) xcalloc(1, sizeof(struct tac_attrib));
49
/* find the last allocated block */
51
while(a->next != NULL)
52
a = a->next; /* a holds last allocated block */
54
a->next = (struct tac_attrib *) xcalloc(1, sizeof(struct tac_attrib));
55
a = a->next; /* set current block pointer to the new one */
58
if ( sep != '=' && sep != '*' ) {
63
a->attr_len=total_len;
64
a->attr = (char *) xcalloc(1, total_len+1);
65
bcopy(name, a->attr, l1); /* paste name */
66
*(a->attr+l1)=sep; /* insert seperator "[=*]" */
67
bcopy(value, (a->attr+l1+1), l2); /* paste value */
68
*(a->attr+total_len) = '\0'; /* add 0 for safety */
69
a->next = NULL; /* make sure it's null */
72
void tac_free_attrib(struct tac_attrib **attr) {
81
/* find last allocated block */