Coverage Report

Created: 2026-08-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/strongswan/src/libimcv/generic/generic_attr_chunk.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2015 Andreas Steffen
3
 *
4
 * Copyright (C) secunet Security Networks AG
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License as published by the
8
 * Free Software Foundation; either version 2 of the License, or (at your
9
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
10
 *
11
 * This program is distributed in the hope that it will be useful, but
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
 * for more details.
15
 */
16
17
#include "generic_attr_chunk.h"
18
19
#include <imcv.h>
20
#include <pen/pen.h>
21
#include <utils/debug.h>
22
23
typedef struct private_generic_attr_chunk_t private_generic_attr_chunk_t;
24
25
/**
26
 * Private data of an generic_attr_chunk_t object.
27
 */
28
struct private_generic_attr_chunk_t {
29
30
  /**
31
   * Public members of generic_attr_chunk_t
32
   */
33
  generic_attr_chunk_t public;
34
35
  /**
36
   * Vendor-specific attribute type
37
   */
38
  pen_type_t type;
39
40
  /**
41
   * Length of attribute value
42
   */
43
  size_t length;
44
45
  /**
46
   * Fixed size of attribute value, set to 0 if dynamic
47
   */
48
  size_t size;
49
50
  /**
51
   * Attribute value or segment
52
   */
53
  chunk_t value;
54
55
  /**
56
   * Noskip flag
57
   */
58
  bool noskip_flag;
59
60
  /**
61
   * Reference count
62
   */
63
  refcount_t ref;
64
};
65
66
METHOD(pa_tnc_attr_t, get_type, pen_type_t,
67
  private_generic_attr_chunk_t *this)
68
2.54k
{
69
2.54k
  return this->type;
70
2.54k
}
71
72
METHOD(pa_tnc_attr_t, get_value, chunk_t,
73
  private_generic_attr_chunk_t *this)
74
1.53k
{
75
1.53k
  return this->value;
76
1.53k
}
77
78
METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
79
  private_generic_attr_chunk_t *this)
80
1.47k
{
81
1.47k
  return this->noskip_flag;
82
1.47k
}
83
84
METHOD(pa_tnc_attr_t, set_noskip_flag,void,
85
  private_generic_attr_chunk_t *this, bool noskip)
86
0
{
87
0
  this->noskip_flag = noskip;
88
0
}
89
90
METHOD(pa_tnc_attr_t, build, void,
91
  private_generic_attr_chunk_t *this)
92
0
{
93
0
  return;
94
0
}
95
96
METHOD(pa_tnc_attr_t, process, status_t,
97
  private_generic_attr_chunk_t *this, uint32_t *offset)
98
1.53k
{
99
1.53k
  enum_name_t *pa_attr_names DBG_UNUSED;
100
1.53k
  *offset = 0;
101
102
1.53k
  if (this->value.len < this->length)
103
0
  {
104
0
    return NEED_MORE;
105
0
  }
106
1.53k
  pa_attr_names = imcv_pa_tnc_attributes->get_names(imcv_pa_tnc_attributes,
107
1.53k
                            this->type.vendor_id);
108
109
1.53k
  if ((this->size == 0 && this->value.len > this->length) ||
110
1.53k
    (this->size != 0 && this->value.len != this->size))
111
57
  {
112
57
    DBG1(DBG_TNC, "inconsistent length of %N/%N string attribute",
113
57
       pen_names, this->type.vendor_id, pa_attr_names, this->type.type);
114
57
    return FAILED;
115
57
  }
116
117
1.47k
  return SUCCESS;
118
1.53k
}
119
120
METHOD(pa_tnc_attr_t, add_segment, void,
121
  private_generic_attr_chunk_t *this, chunk_t segment)
122
0
{
123
0
  this->value = chunk_cat("mc", this->value, segment);
124
0
}
125
126
METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
127
  private_generic_attr_chunk_t *this)
128
0
{
129
0
  ref_get(&this->ref);
130
0
  return &this->public.pa_tnc_attribute;
131
0
}
132
133
METHOD(pa_tnc_attr_t, destroy, void,
134
  private_generic_attr_chunk_t *this)
135
1.53k
{
136
1.53k
  if (ref_put(&this->ref))
137
1.53k
  {
138
1.53k
    free(this->value.ptr);
139
1.53k
    free(this);
140
1.53k
  }
141
1.53k
}
142
143
/**
144
 * Described in header.
145
 */
146
pa_tnc_attr_t *generic_attr_chunk_create_from_data(size_t length, chunk_t value,
147
                           size_t size, pen_type_t type)
148
1.53k
{
149
1.53k
  private_generic_attr_chunk_t *this;
150
151
1.53k
  INIT(this,
152
1.53k
    .public = {
153
1.53k
      .pa_tnc_attribute = {
154
1.53k
        .get_type = _get_type,
155
1.53k
        .get_value = _get_value,
156
1.53k
        .get_noskip_flag = _get_noskip_flag,
157
1.53k
        .set_noskip_flag = _set_noskip_flag,
158
1.53k
        .build = _build,
159
1.53k
        .process = _process,
160
1.53k
        .add_segment = _add_segment,
161
1.53k
        .get_ref = _get_ref,
162
1.53k
        .destroy = _destroy,
163
1.53k
      },
164
1.53k
    },
165
1.53k
    .type = type,
166
1.53k
    .length = length,
167
1.53k
    .size = size,
168
1.53k
    .value = chunk_clone(value),
169
1.53k
    .ref = 1,
170
1.53k
  );
171
172
1.53k
  return &this->public.pa_tnc_attribute;
173
1.53k
}
174
175
/**
176
 * Described in header.
177
 */
178
pa_tnc_attr_t *generic_attr_chunk_create(chunk_t value, pen_type_t type)
179
0
{
180
0
  return generic_attr_chunk_create_from_data(value.len, value,
181
0
                         value.len, type);
182
0
}
183