72
67
INET_ADDRSTRLEN, INET6_ADDRSTRLEN
74
69
#include <unistd.h> /* close(), SEEK_SET, off_t, write(),
75
getuid(), getgid(), seteuid(),
77
#include <arpa/inet.h> /* inet_pton(), htons, inet_ntop() */
70
getuid(), getgid(), setuid(),
72
#include <arpa/inet.h> /* inet_pton(), htons */
78
73
#include <iso646.h> /* not, or, and */
79
74
#include <argp.h> /* struct argp_option, error_t, struct
80
75
argp_state, struct argp,
81
76
argp_parse(), ARGP_KEY_ARG,
82
77
ARGP_KEY_END, ARGP_ERR_UNKNOWN */
83
78
#include <signal.h> /* sigemptyset(), sigaddset(),
84
sigaction(), SIGTERM, sig_atomic_t,
86
#include <sysexits.h> /* EX_OSERR, EX_USAGE, EX_UNAVAILABLE,
87
EX_NOHOST, EX_IOERR, EX_PROTOCOL */
79
sigaction(), SIGTERM, sigaction,
90
83
#include <sys/klog.h> /* klogctl() */
188
155
return buffer_capacity;
191
/* Add server to set of servers to retry periodically */
192
int add_server(const char *ip, uint16_t port,
193
AvahiIfIndex if_index,
196
server *new_server = malloc(sizeof(server));
197
if(new_server == NULL){
198
perror_plus("malloc");
201
*new_server = (server){ .ip = strdup(ip),
203
.if_index = if_index,
205
if(new_server->ip == NULL){
206
perror_plus("strdup");
209
/* Special case of first server */
210
if (mc.current_server == NULL){
211
new_server->next = new_server;
212
new_server->prev = new_server;
213
mc.current_server = new_server;
214
/* Place the new server last in the list */
216
new_server->next = mc.current_server;
217
new_server->prev = mc.current_server->prev;
218
new_server->prev->next = new_server;
219
mc.current_server->prev = new_server;
221
ret = clock_gettime(CLOCK_MONOTONIC, &mc.current_server->last_seen);
223
perror_plus("clock_gettime");
230
159
* Initialize GPGME.
232
161
static bool init_gpgme(const char *seckey,
233
162
const char *pubkey, const char *tempdir){
234
164
gpgme_error_t rc;
235
165
gpgme_engine_info_t engine_info;
1074
/* Signal handler that stops main loop after SIGTERM */
1075
static void handle_sigterm(int sig){
876
sig_atomic_t quit_now = 0;
878
/* stop main loop after sigterm has been called */
879
static void handle_sigterm(__attribute__((unused)) int sig){
1080
signal_received = sig;
1081
884
int old_errno = errno;
1082
/* set main loop to exit */
1083
885
if(mc.simple_poll != NULL){
1084
886
avahi_simple_poll_quit(mc.simple_poll);
1086
888
errno = old_errno;
1089
bool get_flags(const char *ifname, struct ifreq *ifr){
1092
int s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1094
perror_plus("socket");
1097
strcpy(ifr->ifr_name, ifname);
1098
ret = ioctl(s, SIOCGIFFLAGS, ifr);
1101
perror_plus("ioctl SIOCGIFFLAGS");
1108
bool good_flags(const char *ifname, const struct ifreq *ifr){
1110
/* Reject the loopback device */
1111
if(ifr->ifr_flags & IFF_LOOPBACK){
1113
fprintf(stderr, "Rejecting loopback interface \"%s\"\n",
1118
/* Accept point-to-point devices only if connect_to is specified */
1119
if(connect_to != NULL and (ifr->ifr_flags & IFF_POINTOPOINT)){
1121
fprintf(stderr, "Accepting point-to-point interface \"%s\"\n",
1126
/* Otherwise, reject non-broadcast-capable devices */
1127
if(not (ifr->ifr_flags & IFF_BROADCAST)){
1129
fprintf(stderr, "Rejecting non-broadcast interface \"%s\"\n",
1134
/* Reject non-ARP interfaces (including dummy interfaces) */
1135
if(ifr->ifr_flags & IFF_NOARP){
1137
fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n", ifname);
1142
/* Accept this device */
1144
fprintf(stderr, "Interface \"%s\" is good\n", ifname);
1150
* This function determines if a directory entry in /sys/class/net
1151
* corresponds to an acceptable network device.
1152
* (This function is passed to scandir(3) as a filter function.)
1154
int good_interface(const struct dirent *if_entry){
1155
if(if_entry->d_name[0] == '.'){
1160
if(not get_flags(if_entry->d_name, &ifr)){
1162
fprintf(stderr, "Failed to get flags for interface \"%s\"\n",
1168
if(not good_flags(if_entry->d_name, &ifr)){
1175
* This function determines if a directory entry in /sys/class/net
1176
* corresponds to an acceptable network device which is up.
1177
* (This function is passed to scandir(3) as a filter function.)
1179
int up_interface(const struct dirent *if_entry){
1180
if(if_entry->d_name[0] == '.'){
1185
if(not get_flags(if_entry->d_name, &ifr)){
1187
fprintf(stderr, "Failed to get flags for interface \"%s\"\n",
1193
/* Reject down interfaces */
1194
if(not (ifr.ifr_flags & IFF_UP)){
1196
fprintf(stderr, "Rejecting down interface \"%s\"\n",
1202
/* Reject non-running interfaces */
1203
if(not (ifr.ifr_flags & IFF_RUNNING)){
1205
fprintf(stderr, "Rejecting non-running interface \"%s\"\n",
1211
if(not good_flags(if_entry->d_name, &ifr)){
1217
int notdotentries(const struct dirent *direntry){
1218
/* Skip "." and ".." */
1219
if(direntry->d_name[0] == '.'
1220
and (direntry->d_name[1] == '\0'
1221
or (direntry->d_name[1] == '.'
1222
and direntry->d_name[2] == '\0'))){
1228
/* Is this directory entry a runnable program? */
1229
int runnable_hook(const struct dirent *direntry){
1233
if((direntry->d_name)[0] == '\0'){
1238
/* Save pointer to last character */
1239
char *end = strchr(direntry->d_name, '\0')-1;
1246
if(((direntry->d_name)[0] == '#')
1248
/* Temporary #name# */
1252
/* XXX more rules here */
1254
ret = stat(direntry->d_name, &st);
1257
perror_plus("Could not stat plugin");
1261
if(not (S_ISREG(st.st_mode))){
1262
/* Not a regular file */
1265
if(not (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))){
1266
/* Not executable */
1272
int avahi_loop_with_timeout(AvahiSimplePoll *s, int retry_interval){
1274
struct timespec now;
1275
struct timespec waited_time;
1276
intmax_t block_time;
1279
if(mc.current_server == NULL){
1282
"Wait until first server is found. No timeout!\n");
1284
ret = avahi_simple_poll_iterate(s, -1);
1287
fprintf(stderr, "Check current_server if we should run it,"
1290
/* the current time */
1291
ret = clock_gettime(CLOCK_MONOTONIC, &now);
1293
perror_plus("clock_gettime");
1296
/* Calculating in ms how long time between now and server
1297
who we visted longest time ago. Now - last seen. */
1298
waited_time.tv_sec = (now.tv_sec
1299
- mc.current_server->last_seen.tv_sec);
1300
waited_time.tv_nsec = (now.tv_nsec
1301
- mc.current_server->last_seen.tv_nsec);
1302
/* total time is 10s/10,000ms.
1303
Converting to s from ms by dividing by 1,000,
1304
and ns to ms by dividing by 1,000,000. */
1305
block_time = ((retry_interval
1306
- ((intmax_t)waited_time.tv_sec * 1000))
1307
- ((intmax_t)waited_time.tv_nsec / 1000000));
1310
fprintf(stderr, "Blocking for %" PRIdMAX " ms\n", block_time);
1313
if(block_time <= 0){
1314
ret = start_mandos_communication(mc.current_server->ip,
1315
mc.current_server->port,
1316
mc.current_server->if_index,
1317
mc.current_server->af);
1319
avahi_simple_poll_quit(mc.simple_poll);
1322
ret = clock_gettime(CLOCK_MONOTONIC,
1323
&mc.current_server->last_seen);
1325
perror_plus("clock_gettime");
1328
mc.current_server = mc.current_server->next;
1329
block_time = 0; /* Call avahi to find new Mandos
1330
servers, but don't block */
1333
ret = avahi_simple_poll_iterate(s, (int)block_time);
1336
if (ret > 0 or errno != EINTR) {
1337
return (ret != 1) ? ret : 0;
1343
891
int main(int argc, char *argv[]){
1344
892
AvahiSServiceBrowser *sb = NULL;
1475
987
delay = strtof(arg, &tmp);
1476
988
if(errno != 0 or tmp == arg or *tmp != '\0'){
1477
argp_error(state, "Bad delay");
1479
case 132: /* --retry */
1481
retry_interval = strtod(arg, &tmp);
1482
if(errno != 0 or tmp == arg or *tmp != '\0'
1483
or (retry_interval * 1000) > INT_MAX
1484
or retry_interval < 0){
1485
argp_error(state, "Bad retry interval");
989
fprintf(stderr, "Bad delay\n");
1489
* These reproduce what we would get without ARGP_NO_HELP
1491
case '?': /* --help */
1492
argp_state_help(state, state->out_stream,
1493
(ARGP_HELP_STD_HELP | ARGP_HELP_EXIT_ERR)
1494
& ~(unsigned int)ARGP_HELP_EXIT_OK);
1495
case -3: /* --usage */
1496
argp_state_help(state, state->out_stream,
1497
ARGP_HELP_USAGE | ARGP_HELP_EXIT_ERR);
1498
case 'V': /* --version */
1499
fprintf(state->out_stream, "%s\n", argp_program_version);
1500
exit(argp_err_exit_status);
1503
998
return ARGP_ERR_UNKNOWN;
1508
1003
struct argp argp = { .options = options, .parser = parse_opt,
1509
1004
.args_doc = "",
1510
1005
.doc = "Mandos client -- Get and decrypt"
1511
1006
" passwords from a Mandos server" };
1512
ret = argp_parse(&argp, argc, argv,
1513
ARGP_IN_ORDER | ARGP_NO_HELP, 0, NULL);
1520
perror_plus("argp_parse");
1521
exitcode = EX_OSERR;
1524
exitcode = EX_USAGE;
1530
/* Work around Debian bug #633582:
1531
<http://bugs.debian.org/633582> */
1534
/* Re-raise priviliges */
1538
perror_plus("seteuid");
1541
if(strcmp(seckey, PATHDIR "/" SECKEY) == 0){
1542
int seckey_fd = open(seckey, O_RDONLY);
1543
if(seckey_fd == -1){
1544
perror_plus("open");
1546
ret = (int)TEMP_FAILURE_RETRY(fstat(seckey_fd, &st));
1548
perror_plus("fstat");
1550
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1551
ret = fchown(seckey_fd, uid, gid);
1553
perror_plus("fchown");
1557
TEMP_FAILURE_RETRY(close(seckey_fd));
1561
if(strcmp(pubkey, PATHDIR "/" PUBKEY) == 0){
1562
int pubkey_fd = open(pubkey, O_RDONLY);
1563
if(pubkey_fd == -1){
1564
perror_plus("open");
1566
ret = (int)TEMP_FAILURE_RETRY(fstat(pubkey_fd, &st));
1568
perror_plus("fstat");
1570
if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
1571
ret = fchown(pubkey_fd, uid, gid);
1573
perror_plus("fchown");
1577
TEMP_FAILURE_RETRY(close(pubkey_fd));
1581
/* Lower privileges */
1585
perror_plus("seteuid");
1589
/* Find network hooks and run them */
1591
struct dirent **direntries;
1592
struct dirent *direntry;
1593
int numhooks = scandir(HOOKDIR, &direntries, runnable_hook,
1595
int devnull = open("/dev/null", O_RDONLY);
1596
for(int i = 0; i < numhooks; i++){
1597
direntry = direntries[0];
1598
char *fullname = NULL;
1599
ret = asprintf(&fullname, "%s/%s", tempdir,
1602
perror_plus("asprintf");
1605
pid_t hook_pid = fork();
1608
dup2(devnull, STDIN_FILENO);
1610
dup2(STDERR_FILENO, STDOUT_FILENO);
1611
setenv("DEVICE", interface, 1);
1612
setenv("VERBOSE", debug ? "1" : "0", 1);
1613
setenv("MODE", "start", 1);
1614
/* setenv( XXX more here */
1615
ret = execl(fullname, direntry->d_name, "start", NULL);
1616
perror_plus("execl");
1007
ret = argp_parse(&argp, argc, argv, 0, 0, NULL);
1008
if(ret == ARGP_ERR_UNKNOWN){
1009
fprintf(stderr, "Unknown error while parsing arguments\n");
1010
exitcode = EXIT_FAILURE;
1627
1016
avahi_set_log_function(empty_log);
1630
if(interface[0] == '\0'){
1631
struct dirent **direntries;
1632
/* First look for interfaces that are up */
1633
ret = scandir(sys_class_net, &direntries, up_interface,
1636
/* No up interfaces, look for any good interfaces */
1638
ret = scandir(sys_class_net, &direntries, good_interface,
1642
/* Pick the first interface returned */
1643
interface = strdup(direntries[0]->d_name);
1645
fprintf(stderr, "Using interface \"%s\"\n", interface);
1647
if(interface == NULL){
1648
perror_plus("malloc");
1650
exitcode = EXIT_FAILURE;
1656
fprintf(stderr, "Could not find a network interface\n");
1657
exitcode = EXIT_FAILURE;
1662
1019
/* Initialize Avahi early so avahi_simple_poll_quit() can be called
1663
1020
from the signal handler */
1664
1021
/* Initialize the pseudo-RNG for Avahi */
1666
1023
mc.simple_poll = avahi_simple_poll_new();
1667
1024
if(mc.simple_poll == NULL){
1668
1025
fprintf(stderr, "Avahi: Failed to create simple poll object.\n");
1669
exitcode = EX_UNAVAILABLE;
1026
exitcode = EXIT_FAILURE;
1673
1030
sigemptyset(&sigterm_action.sa_mask);
1674
1031
ret = sigaddset(&sigterm_action.sa_mask, SIGINT);
1676
perror_plus("sigaddset");
1677
exitcode = EX_OSERR;
1033
perror("sigaddset");
1034
exitcode = EXIT_FAILURE;
1680
1037
ret = sigaddset(&sigterm_action.sa_mask, SIGHUP);
1682
perror_plus("sigaddset");
1683
exitcode = EX_OSERR;
1039
perror("sigaddset");
1040
exitcode = EXIT_FAILURE;
1686
1043
ret = sigaddset(&sigterm_action.sa_mask, SIGTERM);
1688
perror_plus("sigaddset");
1689
exitcode = EX_OSERR;
1692
/* Need to check if the handler is SIG_IGN before handling:
1693
| [[info:libc:Initial Signal Actions]] |
1694
| [[info:libc:Basic Signal Handling]] |
1696
ret = sigaction(SIGINT, NULL, &old_sigterm_action);
1698
perror_plus("sigaction");
1701
if(old_sigterm_action.sa_handler != SIG_IGN){
1702
ret = sigaction(SIGINT, &sigterm_action, NULL);
1704
perror_plus("sigaction");
1705
exitcode = EX_OSERR;
1709
ret = sigaction(SIGHUP, NULL, &old_sigterm_action);
1711
perror_plus("sigaction");
1714
if(old_sigterm_action.sa_handler != SIG_IGN){
1715
ret = sigaction(SIGHUP, &sigterm_action, NULL);
1717
perror_plus("sigaction");
1718
exitcode = EX_OSERR;
1722
ret = sigaction(SIGTERM, NULL, &old_sigterm_action);
1724
perror_plus("sigaction");
1727
if(old_sigterm_action.sa_handler != SIG_IGN){
1728
ret = sigaction(SIGTERM, &sigterm_action, NULL);
1730
perror_plus("sigaction");
1731
exitcode = EX_OSERR;
1045
perror("sigaddset");
1046
exitcode = EXIT_FAILURE;
1049
ret = sigaction(SIGTERM, &sigterm_action, &old_sigterm_action);
1051
perror("sigaction");
1052
exitcode = EXIT_FAILURE;
1736
1056
/* If the interface is down, bring it up */
1737
if(strcmp(interface, "none") != 0){
1738
if_index = (AvahiIfIndex) if_nametoindex(interface);
1740
fprintf(stderr, "No such interface: \"%s\"\n", interface);
1741
exitcode = EX_UNAVAILABLE;
1749
/* Re-raise priviliges */
1753
perror_plus("seteuid");
1057
if(interface[0] != '\0'){
1756
1058
#ifdef __linux__
1757
1059
/* Lower kernel loglevel to KERN_NOTICE to avoid KERN_INFO
1758
messages about the network interface to mess up the prompt */
1060
messages to mess up the prompt */
1759
1061
ret = klogctl(8, NULL, 5);
1760
1062
bool restore_loglevel = true;
1762
1064
restore_loglevel = false;
1763
perror_plus("klogctl");
1765
1067
#endif /* __linux__ */
1767
1069
sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1769
perror_plus("socket");
1770
exitcode = EX_OSERR;
1072
exitcode = EXIT_FAILURE;
1771
1073
#ifdef __linux__
1772
1074
if(restore_loglevel){
1773
1075
ret = klogctl(7, NULL, 0);
1775
perror_plus("klogctl");
1778
1080
#endif /* __linux__ */
1779
/* Lower privileges */
1783
perror_plus("seteuid");
1787
1083
strcpy(network.ifr_name, interface);
1788
1084
ret = ioctl(sd, SIOCGIFFLAGS, &network);
1790
perror_plus("ioctl SIOCGIFFLAGS");
1086
perror("ioctl SIOCGIFFLAGS");
1791
1087
#ifdef __linux__
1792
1088
if(restore_loglevel){
1793
1089
ret = klogctl(7, NULL, 0);
1795
perror_plus("klogctl");
1798
1094
#endif /* __linux__ */
1799
exitcode = EX_OSERR;
1800
/* Lower privileges */
1804
perror_plus("seteuid");
1095
exitcode = EXIT_FAILURE;
1808
1098
if((network.ifr_flags & IFF_UP) == 0){
1809
1099
network.ifr_flags |= IFF_UP;
1810
take_down_interface = true;
1811
1100
ret = ioctl(sd, SIOCSIFFLAGS, &network);
1813
take_down_interface = false;
1814
perror_plus("ioctl SIOCSIFFLAGS +IFF_UP");
1815
exitcode = EX_OSERR;
1102
perror("ioctl SIOCSIFFLAGS");
1103
exitcode = EXIT_FAILURE;
1816
1104
#ifdef __linux__
1817
1105
if(restore_loglevel){
1818
1106
ret = klogctl(7, NULL, 0);
1820
perror_plus("klogctl");
1823
1111
#endif /* __linux__ */
1824
/* Lower privileges */
1828
perror_plus("seteuid");
1833
/* Sleep checking until interface is running.
1834
Check every 0.25s, up to total time of delay */
1115
/* sleep checking until interface is running */
1835
1116
for(int i=0; i < delay * 4; i++){
1836
1117
ret = ioctl(sd, SIOCGIFFLAGS, &network);
1838
perror_plus("ioctl SIOCGIFFLAGS");
1119
perror("ioctl SIOCGIFFLAGS");
1839
1120
} else if(network.ifr_flags & IFF_RUNNING){
1842
1123
struct timespec sleeptime = { .tv_nsec = 250000000 };
1843
1124
ret = nanosleep(&sleeptime, NULL);
1844
1125
if(ret == -1 and errno != EINTR){
1845
perror_plus("nanosleep");
1126
perror("nanosleep");
1848
if(not take_down_interface){
1849
/* We won't need the socket anymore */
1850
ret = (int)TEMP_FAILURE_RETRY(close(sd));
1852
perror_plus("close");
1129
ret = (int)TEMP_FAILURE_RETRY(close(sd));
1855
1133
#ifdef __linux__
1856
1134
if(restore_loglevel){
1857
1135
/* Restores kernel loglevel to default */
1858
1136
ret = klogctl(7, NULL, 0);
1860
perror_plus("klogctl");
1863
1141
#endif /* __linux__ */
1864
/* Lower privileges */
1866
if(take_down_interface){
1867
/* Lower privileges */
1870
perror_plus("seteuid");
1873
/* Lower privileges permanently */
1876
perror_plus("setuid");
1885
1158
ret = init_gnutls_global(pubkey, seckey);
1887
1160
fprintf(stderr, "init_gnutls_global failed\n");
1888
exitcode = EX_UNAVAILABLE;
1161
exitcode = EXIT_FAILURE;
1891
1164
gnutls_initialized = true;
1898
1167
if(mkdtemp(tempdir) == NULL){
1899
perror_plus("mkdtemp");
1902
1171
tempdir_created = true;
1908
1173
if(not init_gpgme(pubkey, seckey, tempdir)){
1909
1174
fprintf(stderr, "init_gpgme failed\n");
1910
exitcode = EX_UNAVAILABLE;
1175
exitcode = EXIT_FAILURE;
1913
1178
gpgme_initialized = true;
1181
if(interface[0] != '\0'){
1182
if_index = (AvahiIfIndex) if_nametoindex(interface);
1184
fprintf(stderr, "No such interface: \"%s\"\n", interface);
1185
exitcode = EXIT_FAILURE;
1920
1190
if(connect_to != NULL){
1923
1193
char *address = strrchr(connect_to, ':');
1924
1194
if(address == NULL){
1925
1195
fprintf(stderr, "No colon in address\n");
1926
exitcode = EX_USAGE;
1196
exitcode = EXIT_FAILURE;
1936
1201
tmpmax = strtoimax(address+1, &tmp, 10);
1937
1202
if(errno != 0 or tmp == address+1 or *tmp != '\0'
1938
1203
or tmpmax != (uint16_t)tmpmax){
1939
1204
fprintf(stderr, "Bad port number\n");
1940
exitcode = EX_USAGE;
1205
exitcode = EXIT_FAILURE;
1948
1208
port = (uint16_t)tmpmax;
1949
1209
*address = '\0';
1210
address = connect_to;
1950
1211
/* Colon in address indicates IPv6 */
1952
if(strchr(connect_to, ':') != NULL){
1213
if(strchr(address, ':') != NULL){
1954
/* Accept [] around IPv6 address - see RFC 5952 */
1955
if(connect_to[0] == '[' and address[-1] == ']')
1963
address = connect_to;
1969
while(not quit_now){
1970
ret = start_mandos_communication(address, port, if_index, af);
1971
if(quit_now or ret == 0){
1975
fprintf(stderr, "Retrying in %d seconds\n",
1976
(int)retry_interval);
1978
sleep((int)retry_interval);
1218
ret = start_mandos_communication(address, port, if_index, af);
1220
exitcode = EXIT_FAILURE;
1982
1222
exitcode = EXIT_SUCCESS;
1993
1228
AvahiServerConfig config;
1994
1229
/* Do not publish any local Zeroconf records */
2072
1294
if(gpgme_initialized){
2073
1295
gpgme_release(mc.ctx);
2076
/* Cleans up the circular linked list of Mandos servers the client
2078
if(mc.current_server != NULL){
2079
mc.current_server->prev->next = NULL;
2080
while(mc.current_server != NULL){
2081
server *next = mc.current_server->next;
2082
free(mc.current_server);
2083
mc.current_server = next;
2087
/* XXX run network hooks "stop" here */
2089
/* Take down the network interface */
2090
if(take_down_interface){
2091
/* Re-raise priviliges */
2095
perror_plus("seteuid");
2098
ret = ioctl(sd, SIOCGIFFLAGS, &network);
2100
perror_plus("ioctl SIOCGIFFLAGS");
2101
} else if(network.ifr_flags & IFF_UP) {
2102
network.ifr_flags &= ~(short)IFF_UP; /* clear flag */
2103
ret = ioctl(sd, SIOCSIFFLAGS, &network);
2105
perror_plus("ioctl SIOCSIFFLAGS -IFF_UP");
2108
ret = (int)TEMP_FAILURE_RETRY(close(sd));
2110
perror_plus("close");
2112
/* Lower privileges permanently */
2116
perror_plus("setuid");
2121
/* Removes the GPGME temp directory and all files inside */
1298
/* Removes the temp directory used by GPGME */
2122
1299
if(tempdir_created){
2123
struct dirent **direntries = NULL;
2124
struct dirent *direntry = NULL;
2125
int numentries = scandir(tempdir, &direntries, notdotentries,
2127
if (numentries > 0){
2128
for(int i = 0; i < numentries; i++){
2129
direntry = direntries[i];
1301
struct dirent *direntry;
1302
d = opendir(tempdir);
1304
if(errno != ENOENT){
1309
direntry = readdir(d);
1310
if(direntry == NULL){
1313
/* Skip "." and ".." */
1314
if(direntry->d_name[0] == '.'
1315
and (direntry->d_name[1] == '\0'
1316
or (direntry->d_name[1] == '.'
1317
and direntry->d_name[2] == '\0'))){
2130
1320
char *fullname = NULL;
2131
1321
ret = asprintf(&fullname, "%s/%s", tempdir,
2132
1322
direntry->d_name);
2134
perror_plus("asprintf");
2137
1327
ret = remove(fullname);