1 /* Copyright (C) 2010-2021 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /**
21  * @file
22  * @brief Credential pairs and triples.
23  */
24 
25 #include "credentials.h"
26 
27 #include "strings.h" /* for gvm_append_text */
28 
29 #include <string.h>
30 
31 #undef G_LOG_DOMAIN
32 /**
33  * @brief GLib log domain.
34  */
35 #define G_LOG_DOMAIN "libgvm base"
36 
37 /**
38  * @brief Free credentials.
39  *
40  * Free the members of a credentials pair.
41  *
42  * @param[in]  credentials  Pointer to the credentials.
43  */
44 void
free_credentials(credentials_t * credentials)45 free_credentials (credentials_t *credentials)
46 {
47   g_free (credentials->username);
48   g_free (credentials->password);
49   g_free (credentials->uuid);
50   g_free (credentials->timezone);
51   g_free (credentials->role);
52   g_free (credentials->severity_class);
53   memset (credentials, '\0', sizeof (*credentials));
54 }
55 
56 /**
57  * @brief Append text to the username of a credential pair.
58  *
59  * @param[in]  credentials  Credentials.
60  * @param[in]  text         The text to append.
61  * @param[in]  length       Length of the text.
62  */
63 void
append_to_credentials_username(credentials_t * credentials,const char * text,gsize length)64 append_to_credentials_username (credentials_t *credentials, const char *text,
65                                 gsize length)
66 {
67   gvm_append_text (&credentials->username, text, length);
68 }
69 
70 /**
71  * @brief Append text to the password of a credential pair.
72  *
73  * @param[in]  credentials  Credentials.
74  * @param[in]  text         The text to append.
75  * @param[in]  length       Length of the text.
76  */
77 void
append_to_credentials_password(credentials_t * credentials,const char * text,gsize length)78 append_to_credentials_password (credentials_t *credentials, const char *text,
79                                 gsize length)
80 {
81   gvm_append_text (&credentials->password, text, length);
82 }
83