Line data Source code
1 : /*
2 : SSSD - auth utils helpers
3 :
4 : Copyright (C) Sumit Bose <sbose@redhat.com> 2015
5 :
6 : This program is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3 of the License, or
9 : (at your option) any later version.
10 :
11 : This program is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : GNU General Public License for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with this program. If not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : /* This file is use by SSSD clients and the main daemons. Please do not add
21 : * code which is specific to only one of them. */
22 :
23 : #include <errno.h>
24 :
25 : #include "sss_client/sss_cli.h"
26 :
27 28 : errno_t sss_auth_pack_2fa_blob(const char *fa1, size_t fa1_len,
28 : const char *fa2, size_t fa2_len,
29 : uint8_t *buf, size_t buf_len,
30 : size_t *_2fa_blob_len)
31 : {
32 : size_t c;
33 : uint32_t tmp_uint32_t;
34 :
35 28 : if (fa1 == NULL || *fa1 == '\0' || fa1_len > UINT32_MAX
36 25 : || fa2 == NULL || *fa2 == '\0' || fa2_len > UINT32_MAX
37 22 : || (buf == NULL && buf_len != 0)) {
38 6 : return EINVAL;
39 : }
40 :
41 22 : if (fa1_len == 0) {
42 10 : fa1_len = strlen(fa1);
43 : } else {
44 12 : if (fa1[fa1_len] != '\0') {
45 1 : return EINVAL;
46 : }
47 : }
48 :
49 21 : if (fa2_len == 0) {
50 10 : fa2_len = strlen(fa2);
51 : } else {
52 11 : if (fa2[fa2_len] != '\0') {
53 1 : return EINVAL;
54 : }
55 : }
56 :
57 20 : *_2fa_blob_len = fa1_len + fa2_len + 2 + 2 * sizeof(uint32_t);
58 20 : if (buf == NULL || buf_len < *_2fa_blob_len) {
59 10 : return EAGAIN;
60 : }
61 :
62 10 : c = 0;
63 10 : tmp_uint32_t = (uint32_t) fa1_len + 1;
64 10 : SAFEALIGN_COPY_UINT32(buf, &tmp_uint32_t, &c);
65 10 : tmp_uint32_t = (uint32_t) fa2_len + 1;
66 10 : SAFEALIGN_COPY_UINT32(buf + c, &tmp_uint32_t, &c);
67 :
68 10 : memcpy(buf + c, fa1, fa1_len + 1);
69 10 : c += fa1_len + 1;
70 :
71 10 : memcpy(buf + c, fa2, fa2_len + 1);
72 :
73 10 : return 0;
74 : }
|