Coverage Report

Created: 2023-06-07 06:53

/src/libbde/libbde/libbde_password_keep.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Password keep functions
3
 *
4
 * Copyright (C) 2011-2023, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <byte_stream.h>
24
#include <memory.h>
25
#include <types.h>
26
27
#include "libbde_libcerror.h"
28
#include "libbde_password_keep.h"
29
30
/* Creates a password keep
31
 * Make sure the value password_keep is referencing, is set to NULL
32
 * Returns 1 if successful or -1 on error
33
 */
34
int libbde_password_keep_initialize(
35
     libbde_password_keep_t **password_keep,
36
     libcerror_error_t **error )
37
2.63k
{
38
2.63k
  static char *function = "libbde_password_keep_initialize";
39
40
2.63k
  if( password_keep == NULL )
41
0
  {
42
0
    libcerror_error_set(
43
0
     error,
44
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
45
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
46
0
     "%s: invalid pasword keep.",
47
0
     function );
48
49
0
    return( -1 );
50
0
  }
51
2.63k
  if( *password_keep != NULL )
52
0
  {
53
0
    libcerror_error_set(
54
0
     error,
55
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
56
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
57
0
     "%s: invalid pasword keep value already set.",
58
0
     function );
59
60
0
    return( -1 );
61
0
  }
62
2.63k
  *password_keep = memory_allocate_structure(
63
2.63k
                    libbde_password_keep_t );
64
65
2.63k
  if( *password_keep == NULL )
66
0
  {
67
0
    libcerror_error_set(
68
0
     error,
69
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
70
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
71
0
     "%s: unable to create pasword keep.",
72
0
     function );
73
74
0
    goto on_error;
75
0
  }
76
2.63k
  if( memory_set(
77
2.63k
       *password_keep,
78
2.63k
       0,
79
2.63k
       sizeof( libbde_password_keep_t ) ) == NULL )
80
0
  {
81
0
    libcerror_error_set(
82
0
     error,
83
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
84
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
85
0
     "%s: unable to clear pasword keep.",
86
0
     function );
87
88
0
    memory_free(
89
0
     *password_keep );
90
91
0
    *password_keep = NULL;
92
93
0
    return( -1 );
94
0
  }
95
2.63k
  return( 1 );
96
97
0
on_error:
98
0
  if( *password_keep != NULL )
99
0
  {
100
0
    memory_free(
101
0
     *password_keep );
102
103
0
    *password_keep = NULL;
104
0
  }
105
0
  return( -1 );
106
2.63k
}
107
108
/* Frees a password keep
109
 * Returns 1 if successful or -1 on error
110
 */
111
int libbde_password_keep_free(
112
     libbde_password_keep_t **password_keep,
113
     libcerror_error_t **error )
114
2.63k
{
115
2.63k
  static char *function = "libbde_password_keep_free";
116
2.63k
  int result            = 1;
117
118
2.63k
  if( password_keep == NULL )
119
0
  {
120
0
    libcerror_error_set(
121
0
     error,
122
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
123
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
124
0
     "%s: invalid pasword keep.",
125
0
     function );
126
127
0
    return( -1 );
128
0
  }
129
2.63k
  if( *password_keep != NULL )
130
2.63k
  {
131
2.63k
    if( memory_set(
132
2.63k
         *password_keep,
133
2.63k
         0,
134
2.63k
         sizeof( libbde_password_keep_t ) ) == NULL )
135
0
    {
136
0
      libcerror_error_set(
137
0
       error,
138
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
139
0
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
140
0
       "%s: unable to clear password keep.",
141
0
       function );
142
143
0
      result = -1;
144
0
    }
145
2.63k
    memory_free(
146
2.63k
     *password_keep );
147
148
2.63k
    *password_keep = NULL;
149
2.63k
  }
150
2.63k
  return( result );
151
2.63k
}
152