205
204
perror_plus("strdup");
208
/* Special case of first server */
207
/* unique case of first server */
209
208
if (mc.current_server == NULL){
210
209
new_server->next = new_server;
211
210
new_server->prev = new_server;
212
211
mc.current_server = new_server;
213
/* Place the new server last in the list */
212
/* Placing the new server last in the list */
215
214
new_server->next = mc.current_server;
216
215
new_server->prev = mc.current_server->prev;
286
/* Set GPGME home directory for the OpenPGP engine only */
285
/* Set GPGME home directory for the OpenPGP engine only */
287
286
rc = gpgme_get_engine_info(&engine_info);
288
287
if(rc != GPG_ERR_NO_ERROR){
289
288
fprintf(stderr, "bad gpgme_get_engine_info: %s: %s\n",
1237
1236
block_time = ((retry_interval
1238
1237
- ((intmax_t)waited_time.tv_sec * 1000))
1239
1238
- ((intmax_t)waited_time.tv_nsec / 1000000));
1242
fprintf(stderr, "Blocking for %" PRIdMAX " ms\n", block_time);
1241
fprintf(stderr, "Blocking for %ld ms\n", block_time);
1245
1244
if(block_time <= 0){
1246
1245
ret = start_mandos_communication(mc.current_server->ip,
1247
1246
mc.current_server->port,
1413
1412
retry_interval = strtod(arg, &tmp);
1414
1413
if(errno != 0 or tmp == arg or *tmp != '\0'
1415
or (retry_interval * 1000) > INT_MAX
1416
or retry_interval < 0){
1414
or (retry_interval * 1000) > INT_MAX){
1417
1415
argp_error(state, "Bad retry interval");
1470
1468
perror_plus("seteuid");
1473
if(strcmp(seckey, PATHDIR "/" SECKEY) == 0){
1474
int seckey_fd = open(seckey, O_RDONLY);
1475
if(seckey_fd == -1){
1476
perror_plus("open");
1471
int seckey_fd = open(PATHDIR "/" SECKEY, O_RDONLY);
1472
if(seckey_fd == -1){
1473
perror_plus("open");
1475
ret = (int)TEMP_FAILURE_RETRY(fstat(seckey_fd, &st));
1477
perror_plus("fstat");
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");
1479
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1480
ret = fchown(seckey_fd, uid, gid);
1482
perror_plus("fchown");
1489
TEMP_FAILURE_RETRY(close(seckey_fd));
1486
TEMP_FAILURE_RETRY(close(seckey_fd));
1493
if(strcmp(pubkey, PATHDIR "/" PUBKEY) == 0){
1494
int pubkey_fd = open(pubkey, O_RDONLY);
1495
if(pubkey_fd == -1){
1496
perror_plus("open");
1489
int pubkey_fd = open(PATHDIR "/" PUBKEY, O_RDONLY);
1490
if(pubkey_fd == -1){
1491
perror_plus("open");
1493
ret = (int)TEMP_FAILURE_RETRY(fstat(pubkey_fd, &st));
1495
perror_plus("fstat");
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");
1497
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1498
ret = fchown(pubkey_fd, uid, gid);
1500
perror_plus("fchown");
1509
TEMP_FAILURE_RETRY(close(pubkey_fd));
1504
TEMP_FAILURE_RETRY(close(pubkey_fd));
1513
1507
/* Lower privileges */
1836
1830
port = (uint16_t)tmpmax;
1837
1831
*address = '\0';
1832
address = connect_to;
1838
1833
/* Colon in address indicates IPv6 */
1840
if(strchr(connect_to, ':') != NULL){
1835
if(strchr(address, ':') != NULL){
1842
/* Accept [] around IPv6 address - see RFC 5952 */
1843
if(connect_to[0] == '[' and address[-1] == ']')
1851
address = connect_to;
1857
1845
while(not quit_now){
1858
1846
ret = start_mandos_communication(address, port, if_index, af);
1859
1847
if(quit_now or ret == 0){
1863
fprintf(stderr, "Retrying in %d seconds\n",
1864
(int)retry_interval);
1866
sleep((int)retry_interval);
1850
sleep((int)retry_interval or 1);
1869
1853
if (not quit_now){
1870
1854
exitcode = EXIT_SUCCESS;
2008
1992
if(tempdir_created){
2009
1993
struct dirent **direntries = NULL;
2010
1994
struct dirent *direntry = NULL;
2011
int numentries = scandir(tempdir, &direntries, notdotentries,
2013
if (numentries > 0){
2014
for(int i = 0; i < numentries; i++){
1995
ret = scandir(tempdir, &direntries, notdotentries, alphasort);
1997
for(int i = 0; i < ret; i++){
2015
1998
direntry = direntries[i];
2016
1999
char *fullname = NULL;
2017
2000
ret = asprintf(&fullname, "%s/%s", tempdir,