Added missing noskip_flag setter/getter to some pa_tnc_attr_t constructors
[strongswan.git] / src / libimcv / ietf / ietf_attr_default_pwd_enabled.c
1 /*
2 * Copyright (C) 2012 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "ietf_attr_default_pwd_enabled.h"
17
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <utils/debug.h>
22
23 typedef struct private_ietf_attr_default_pwd_enabled_t private_ietf_attr_default_pwd_enabled_t;
24
25 /**
26 * PA-TNC Factory Default Password Enabled type (see section 4.2.12 of RFC 5792)
27 *
28 * 1 2 3
29 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
30 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 * | Factory Default Password Enabled |
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 */
34
35 #define DEFAULT_PWD_ENABLED_SIZE 4
36
37 /**
38 * Private data of an ietf_attr_default_pwd_enabled_t object.
39 */
40 struct private_ietf_attr_default_pwd_enabled_t {
41
42 /**
43 * Public members of ietf_attr_default_pwd_enabled_t
44 */
45 ietf_attr_default_pwd_enabled_t public;
46
47 /**
48 * Vendor-specific attribute type
49 */
50 pen_type_t type;
51
52 /**
53 * Attribute value
54 */
55 chunk_t value;
56
57 /**
58 * Noskip flag
59 */
60 bool noskip_flag;
61
62 /**
63 * Factory Default Password Enabled status
64 */
65 bool status;
66
67 /**
68 * Reference count
69 */
70 refcount_t ref;
71 };
72
73 METHOD(pa_tnc_attr_t, get_type, pen_type_t,
74 private_ietf_attr_default_pwd_enabled_t *this)
75 {
76 return this->type;
77 }
78
79 METHOD(pa_tnc_attr_t, get_value, chunk_t,
80 private_ietf_attr_default_pwd_enabled_t *this)
81 {
82 return this->value;
83 }
84
85 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
86 private_ietf_attr_default_pwd_enabled_t *this)
87 {
88 return this->noskip_flag;
89 }
90
91 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
92 private_ietf_attr_default_pwd_enabled_t *this, bool noskip)
93 {
94 this->noskip_flag = noskip;
95 }
96
97 METHOD(pa_tnc_attr_t, build, void,
98 private_ietf_attr_default_pwd_enabled_t *this)
99 {
100 bio_writer_t *writer;
101
102 if (this->value.ptr)
103 {
104 return;
105 }
106 writer = bio_writer_create(DEFAULT_PWD_ENABLED_SIZE);
107 writer->write_uint32(writer, this->status);
108
109 this->value = chunk_clone(writer->get_buf(writer));
110 writer->destroy(writer);
111 }
112
113 METHOD(pa_tnc_attr_t, process, status_t,
114 private_ietf_attr_default_pwd_enabled_t *this, u_int32_t *offset)
115 {
116 bio_reader_t *reader;
117 u_int32_t status;
118
119 *offset = 0;
120
121 if (this->value.len != DEFAULT_PWD_ENABLED_SIZE)
122 {
123 DBG1(DBG_TNC, "incorrect size for IETF factory default password "
124 "enabled attribute");
125 return FAILED;
126 }
127 reader = bio_reader_create(this->value);
128 reader->read_uint32(reader, &status);
129 reader->destroy(reader);
130
131 if (status > TRUE)
132 {
133 DBG1(DBG_TNC, "IETF factory default password enabled field "
134 "has unknown value %u", status);
135 return FAILED;
136 }
137 this->status = status;
138
139 return SUCCESS;
140 }
141
142 METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
143 private_ietf_attr_default_pwd_enabled_t *this)
144 {
145 ref_get(&this->ref);
146 return &this->public.pa_tnc_attribute;
147 }
148
149 METHOD(pa_tnc_attr_t, destroy, void,
150 private_ietf_attr_default_pwd_enabled_t *this)
151 {
152 if (ref_put(&this->ref))
153 {
154 free(this->value.ptr);
155 free(this);
156 }
157 }
158
159 METHOD(ietf_attr_default_pwd_enabled_t, get_status, bool,
160 private_ietf_attr_default_pwd_enabled_t *this)
161 {
162 return this->status;
163 }
164
165 /**
166 * Described in header.
167 */
168 pa_tnc_attr_t *ietf_attr_default_pwd_enabled_create(bool status)
169 {
170 private_ietf_attr_default_pwd_enabled_t *this;
171
172 INIT(this,
173 .public = {
174 .pa_tnc_attribute = {
175 .get_type = _get_type,
176 .get_value = _get_value,
177 .get_noskip_flag = _get_noskip_flag,
178 .set_noskip_flag = _set_noskip_flag,
179 .build = _build,
180 .process = _process,
181 .get_ref = _get_ref,
182 .destroy = _destroy,
183 },
184 .get_status = _get_status,
185 },
186 .type = { PEN_IETF, IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED },
187 .status = status,
188 .ref = 1,
189 );
190
191 return &this->public.pa_tnc_attribute;
192 }
193
194 /**
195 * Described in header.
196 */
197 pa_tnc_attr_t *ietf_attr_default_pwd_enabled_create_from_data(chunk_t data)
198 {
199 private_ietf_attr_default_pwd_enabled_t *this;
200
201 INIT(this,
202 .public = {
203 .pa_tnc_attribute = {
204 .get_type = _get_type,
205 .get_value = _get_value,
206 .get_noskip_flag = _get_noskip_flag,
207 .set_noskip_flag = _set_noskip_flag,
208 .build = _build,
209 .process = _process,
210 .get_ref = _get_ref,
211 .destroy = _destroy,
212 },
213 .get_status = _get_status,
214 },
215 .type = { PEN_IETF, IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED },
216 .value = chunk_clone(data),
217 .ref = 1,
218 );
219
220 return &this->public.pa_tnc_attribute;
221 }
222