9
9
* "browse_callback", and parts of "main".
11
11
* Everything else is
12
* Copyright © 2008-2018 Teddy Hogeborn
13
* Copyright © 2008-2018 Björn Påhlsson
15
* This file is part of Mandos.
17
* Mandos is free software: you can redistribute it and/or modify it
18
* under the terms of the GNU General Public License as published by
19
* the Free Software Foundation, either version 3 of the License, or
20
* (at your option) any later version.
22
* Mandos is distributed in the hope that it will be useful, but
12
* Copyright © 2008-2016 Teddy Hogeborn
13
* Copyright © 2008-2016 Björn Påhlsson
15
* This program is free software: you can redistribute it and/or
16
* modify it under the terms of the GNU General Public License as
17
* published by the Free Software Foundation, either version 3 of the
18
* License, or (at your option) any later version.
20
* This program is distributed in the hope that it will be useful, but
23
21
* WITHOUT ANY WARRANTY; without even the implied warranty of
24
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
23
* General Public License for more details.
27
25
* You should have received a copy of the GNU General Public License
28
* along with Mandos. If not, see <http://www.gnu.org/licenses/>.
26
* along with this program. If not, see
27
* <http://www.gnu.org/licenses/>.
30
29
* Contact the authors at <mandos@recompile.se>.
310
308
gpgme_strsource(rc), gpgme_strerror(rc));
314
gpgme_import_result_t import_result
315
= gpgme_op_import_result(mc->ctx);
316
if((import_result->imported < 1
317
or import_result->not_imported > 0)
318
and import_result->unchanged == 0){
319
fprintf_plus(stderr, "bad gpgme_op_import_results:\n");
321
"The total number of considered keys: %d\n",
322
import_result->considered);
324
"The number of keys without user ID: %d\n",
325
import_result->no_user_id);
327
"The total number of imported keys: %d\n",
328
import_result->imported);
329
fprintf_plus(stderr, "The number of imported RSA keys: %d\n",
330
import_result->imported_rsa);
331
fprintf_plus(stderr, "The number of unchanged keys: %d\n",
332
import_result->unchanged);
333
fprintf_plus(stderr, "The number of new user IDs: %d\n",
334
import_result->new_user_ids);
335
fprintf_plus(stderr, "The number of new sub keys: %d\n",
336
import_result->new_sub_keys);
337
fprintf_plus(stderr, "The number of new signatures: %d\n",
338
import_result->new_signatures);
339
fprintf_plus(stderr, "The number of new revocations: %d\n",
340
import_result->new_revocations);
342
"The total number of secret keys read: %d\n",
343
import_result->secret_read);
345
"The number of imported secret keys: %d\n",
346
import_result->secret_imported);
348
"The number of unchanged secret keys: %d\n",
349
import_result->secret_unchanged);
350
fprintf_plus(stderr, "The number of keys not imported: %d\n",
351
import_result->not_imported);
352
for(gpgme_import_status_t import_status
353
= import_result->imports;
354
import_status != NULL;
355
import_status = import_status->next){
356
fprintf_plus(stderr, "Import status for key: %s\n",
358
if(import_status->result != GPG_ERR_NO_ERROR){
359
fprintf_plus(stderr, "Import result: %s: %s\n",
360
gpgme_strsource(import_status->result),
361
gpgme_strerror(import_status->result));
363
fprintf_plus(stderr, "Key status:\n");
365
import_status->status & GPGME_IMPORT_NEW
366
? "The key was new.\n"
367
: "The key was not new.\n");
369
import_status->status & GPGME_IMPORT_UID
370
? "The key contained new user IDs.\n"
371
: "The key did not contain new user IDs.\n");
373
import_status->status & GPGME_IMPORT_SIG
374
? "The key contained new signatures.\n"
375
: "The key did not contain new signatures.\n");
377
import_status->status & GPGME_IMPORT_SUBKEY
378
? "The key contained new sub keys.\n"
379
: "The key did not contain new sub keys.\n");
381
import_status->status & GPGME_IMPORT_SECRET
382
? "The key contained a secret key.\n"
383
: "The key did not contain a secret key.\n");
493
418
if(result == NULL){
494
419
fprintf_plus(stderr, "gpgme_op_decrypt_result failed\n");
496
if(result->unsupported_algorithm != NULL) {
497
fprintf_plus(stderr, "Unsupported algorithm: %s\n",
498
result->unsupported_algorithm);
500
fprintf_plus(stderr, "Wrong key usage: %s\n",
501
result->wrong_key_usage ? "Yes" : "No");
421
fprintf_plus(stderr, "Unsupported algorithm: %s\n",
422
result->unsupported_algorithm);
423
fprintf_plus(stderr, "Wrong key usage: %u\n",
424
result->wrong_key_usage);
502
425
if(result->file_name != NULL){
503
426
fprintf_plus(stderr, "File name: %s\n", result->file_name);
900
818
/* Set effective uid to 0, return errno */
901
819
__attribute__((warn_unused_result))
902
int raise_privileges(void){
903
int old_errno = errno;
820
error_t raise_privileges(void){
821
error_t old_errno = errno;
822
error_t ret_errno = 0;
905
823
if(seteuid(0) == -1){
908
826
errno = old_errno;
912
830
/* Set effective and real user ID to 0. Return errno. */
913
831
__attribute__((warn_unused_result))
914
int raise_privileges_permanently(void){
915
int old_errno = errno;
916
int ret = raise_privileges();
832
error_t raise_privileges_permanently(void){
833
error_t old_errno = errno;
834
error_t ret_errno = raise_privileges();
918
836
errno = old_errno;
921
839
if(setuid(0) == -1){
924
842
errno = old_errno;
928
846
/* Set effective user ID to unprivileged saved user ID */
929
847
__attribute__((warn_unused_result))
930
int lower_privileges(void){
931
int old_errno = errno;
848
error_t lower_privileges(void){
849
error_t old_errno = errno;
850
error_t ret_errno = 0;
933
851
if(seteuid(uid) == -1){
936
854
errno = old_errno;
940
858
/* Lower privileges permanently */
941
859
__attribute__((warn_unused_result))
942
int lower_privileges_permanently(void){
943
int old_errno = errno;
860
error_t lower_privileges_permanently(void){
861
error_t old_errno = errno;
862
error_t ret_errno = 0;
945
863
if(setuid(uid) == -1){
948
866
errno = old_errno;
952
870
/* Helper function to add_local_route() and delete_local_route() */
2015
int devnull = (int)TEMP_FAILURE_RETRY(open("/dev/null", O_RDONLY));
2017
perror_plus("open(\"/dev/null\", O_RDONLY)");
2020
1912
int numhooks = scandirat(hookdir_fd, ".", &direntries,
2021
1913
runnable_hook, alphasort);
2022
1914
if(numhooks == -1){
2023
1915
perror_plus("scandir");
2027
1918
struct dirent *direntry;
1920
int devnull = (int)TEMP_FAILURE_RETRY(open("/dev/null", O_RDONLY));
1922
perror_plus("open(\"/dev/null\", O_RDONLY)");
2029
1925
for(int i = 0; i < numhooks; i++){
2030
1926
direntry = direntries[i];
2570
2464
.args_doc = "",
2571
2465
.doc = "Mandos client -- Get and decrypt"
2572
2466
" passwords from a Mandos server" };
2573
ret_errno = argp_parse(&argp, argc, argv,
2574
ARGP_IN_ORDER | ARGP_NO_HELP, 0, NULL);
2467
ret = argp_parse(&argp, argc, argv,
2468
ARGP_IN_ORDER | ARGP_NO_HELP, 0, NULL);
2581
2475
perror_plus("argp_parse");
2582
2476
exitcode = EX_OSERR;