286
/* Set GPGME home directory for the OpenPGP engine only */
286
/* Set GPGME home directory for the OpenPGP engine only */
287
287
rc = gpgme_get_engine_info(&engine_info);
288
288
if(rc != GPG_ERR_NO_ERROR){
289
289
fprintf(stderr, "bad gpgme_get_engine_info: %s: %s\n",
1470
1470
perror_plus("seteuid");
1473
int seckey_fd = open(PATHDIR "/" SECKEY, O_RDONLY);
1474
if(seckey_fd == -1){
1475
perror_plus("open");
1477
ret = (int)TEMP_FAILURE_RETRY(fstat(seckey_fd, &st));
1479
perror_plus("fstat");
1473
if(strcmp(seckey, PATHDIR "/" SECKEY) == 0){
1474
int seckey_fd = open(seckey, O_RDONLY);
1475
if(seckey_fd == -1){
1476
perror_plus("open");
1481
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1482
ret = fchown(seckey_fd, uid, gid);
1484
perror_plus("fchown");
1478
ret = (int)TEMP_FAILURE_RETRY(fstat(seckey_fd, &st));
1480
perror_plus("fstat");
1482
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1483
ret = fchown(seckey_fd, uid, gid);
1485
perror_plus("fchown");
1489
TEMP_FAILURE_RETRY(close(seckey_fd));
1488
TEMP_FAILURE_RETRY(close(seckey_fd));
1491
int pubkey_fd = open(PATHDIR "/" PUBKEY, O_RDONLY);
1492
if(pubkey_fd == -1){
1493
perror_plus("open");
1495
ret = (int)TEMP_FAILURE_RETRY(fstat(pubkey_fd, &st));
1497
perror_plus("fstat");
1493
if(strcmp(pubkey, PATHDIR "/" PUBKEY) == 0){
1494
int pubkey_fd = open(pubkey, O_RDONLY);
1495
if(pubkey_fd == -1){
1496
perror_plus("open");
1499
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1500
ret = fchown(pubkey_fd, uid, gid);
1502
perror_plus("fchown");
1498
ret = (int)TEMP_FAILURE_RETRY(fstat(pubkey_fd, &st));
1500
perror_plus("fstat");
1502
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1503
ret = fchown(pubkey_fd, uid, gid);
1505
perror_plus("fchown");
1509
TEMP_FAILURE_RETRY(close(pubkey_fd));
1506
TEMP_FAILURE_RETRY(close(pubkey_fd));
1509
1513
/* Lower privileges */
2004
2008
if(tempdir_created){
2005
2009
struct dirent **direntries = NULL;
2006
2010
struct dirent *direntry = NULL;
2007
ret = scandir(tempdir, &direntries, notdotentries, alphasort);
2009
for(int i = 0; i < ret; i++){
2011
int numentries = scandir(tempdir, &direntries, notdotentries,
2013
if (numentries > 0){
2014
for(int i = 0; i < numentries; i++){
2010
2015
direntry = direntries[i];
2011
2016
char *fullname = NULL;
2012
2017
ret = asprintf(&fullname, "%s/%s", tempdir,