archive_read_add_passphrase.c (302408) | archive_read_add_passphrase.c (305188) |
---|---|
1/*- 2 * Copyright (c) 2014 Michihiro NAKAJIMA 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "archive_platform.h" | 1/*- 2 * Copyright (c) 2014 Michihiro NAKAJIMA 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "archive_platform.h" |
27__FBSDID("$FreeBSD: stable/11/contrib/libarchive/libarchive/archive_read_add_passphrase.c 299529 2016-05-12 10:16:16Z mm $"); | 27__FBSDID("$FreeBSD: stable/11/contrib/libarchive/libarchive/archive_read_add_passphrase.c 305188 2016-09-01 07:53:59Z mm $"); |
28 29#ifdef HAVE_ERRNO_H 30#include <errno.h> 31#endif 32#include "archive_read_private.h" 33 34static void 35add_passphrase_to_tail(struct archive_read *a, --- 84 unchanged lines hidden (view full) --- 120/* 121 * Call this in advance when you start to get a passphrase for decryption 122 * for a entry. 123 */ 124void 125__archive_read_reset_passphrase(struct archive_read *a) 126{ 127 | 28 29#ifdef HAVE_ERRNO_H 30#include <errno.h> 31#endif 32#include "archive_read_private.h" 33 34static void 35add_passphrase_to_tail(struct archive_read *a, --- 84 unchanged lines hidden (view full) --- 120/* 121 * Call this in advance when you start to get a passphrase for decryption 122 * for a entry. 123 */ 124void 125__archive_read_reset_passphrase(struct archive_read *a) 126{ 127 |
128 a->passphrases.candiate = -1; | 128 a->passphrases.candidate = -1; |
129} 130 131/* 132 * Get a passphrase for decryption. 133 */ 134const char * 135__archive_read_next_passphrase(struct archive_read *a) 136{ 137 struct archive_read_passphrase *p; 138 const char *passphrase; 139 | 129} 130 131/* 132 * Get a passphrase for decryption. 133 */ 134const char * 135__archive_read_next_passphrase(struct archive_read *a) 136{ 137 struct archive_read_passphrase *p; 138 const char *passphrase; 139 |
140 if (a->passphrases.candiate < 0) { | 140 if (a->passphrases.candidate < 0) { |
141 /* Count out how many passphrases we have. */ 142 int cnt = 0; 143 144 for (p = a->passphrases.first; p != NULL; p = p->next) 145 cnt++; | 141 /* Count out how many passphrases we have. */ 142 int cnt = 0; 143 144 for (p = a->passphrases.first; p != NULL; p = p->next) 145 cnt++; |
146 a->passphrases.candiate = cnt; | 146 a->passphrases.candidate = cnt; |
147 p = a->passphrases.first; | 147 p = a->passphrases.first; |
148 } else if (a->passphrases.candiate > 1) { | 148 } else if (a->passphrases.candidate > 1) { |
149 /* Rotate a passphrase list. */ | 149 /* Rotate a passphrase list. */ |
150 a->passphrases.candiate--; | 150 a->passphrases.candidate--; |
151 p = remove_passphrases_from_head(a); 152 add_passphrase_to_tail(a, p); | 151 p = remove_passphrases_from_head(a); 152 add_passphrase_to_tail(a, p); |
153 /* Pick a new passphrase candiate up. */ | 153 /* Pick a new passphrase candidate up. */ |
154 p = a->passphrases.first; | 154 p = a->passphrases.first; |
155 } else if (a->passphrases.candiate == 1) { 156 /* This case is that all cadiates failed to decryption. */ 157 a->passphrases.candiate = 0; | 155 } else if (a->passphrases.candidate == 1) { 156 /* This case is that all candidates failed to decrypt. */ 157 a->passphrases.candidate = 0; |
158 if (a->passphrases.first->next != NULL) { 159 /* Rotate a passphrase list. */ 160 p = remove_passphrases_from_head(a); 161 add_passphrase_to_tail(a, p); 162 } 163 p = NULL; | 158 if (a->passphrases.first->next != NULL) { 159 /* Rotate a passphrase list. */ 160 p = remove_passphrases_from_head(a); 161 add_passphrase_to_tail(a, p); 162 } 163 p = NULL; |
164 } else /* There is no passphrase candaite. */ | 164 } else /* There is no passphrase candidate. */ |
165 p = NULL; 166 167 if (p != NULL) 168 passphrase = p->passphrase; 169 else if (a->passphrases.callback != NULL) { 170 /* Get a passphrase through a call-back function 171 * since we tried all passphrases out or we don't 172 * have it. */ 173 passphrase = a->passphrases.callback(&a->archive, 174 a->passphrases.client_data); 175 if (passphrase != NULL) { 176 p = new_read_passphrase(a, passphrase); 177 if (p == NULL) 178 return (NULL); 179 insert_passphrase_to_head(a, p); | 165 p = NULL; 166 167 if (p != NULL) 168 passphrase = p->passphrase; 169 else if (a->passphrases.callback != NULL) { 170 /* Get a passphrase through a call-back function 171 * since we tried all passphrases out or we don't 172 * have it. */ 173 passphrase = a->passphrases.callback(&a->archive, 174 a->passphrases.client_data); 175 if (passphrase != NULL) { 176 p = new_read_passphrase(a, passphrase); 177 if (p == NULL) 178 return (NULL); 179 insert_passphrase_to_head(a, p); |
180 a->passphrases.candiate = 1; | 180 a->passphrases.candidate = 1; |
181 } 182 } else 183 passphrase = NULL; 184 185 return (passphrase); 186} | 181 } 182 } else 183 passphrase = NULL; 184 185 return (passphrase); 186} |