662
if(if_index != AVAHI_IF_UNSPEC and mc->interfaces != NULL){
663
/* Check if the interface is one of the interfaces we are using */
666
char *interface = NULL;
667
while((interface=argz_next(mc->interfaces, mc->interfaces_size,
669
if(if_nametoindex(interface) == (unsigned int)if_index){
677
char interface[IF_NAMESIZE];
678
if(if_indextoname((unsigned int)if_index, interface) == NULL){
679
perror_plus("if_indextoname");
681
fprintf_plus(stderr, "Skipping server on non-used interface"
683
if_indextoname((unsigned int)if_index,
660
691
ret = init_gnutls_session(&session, mc);
1755
1786
int main(int argc, char *argv[]){
1756
1787
mandos_context mc = { .server = NULL, .dh_bits = 1024,
1757
1788
.priority = "SECURE256:!CTYPE-X.509:"
1758
"+CTYPE-OPENPGP", .current_server = NULL };
1789
"+CTYPE-OPENPGP", .current_server = NULL,
1790
.interfaces = NULL, .interfaces_size = 0 };
1759
1791
AvahiSServiceBrowser *sb = NULL;
1760
1792
error_t ret_errno;
1762
1794
intmax_t tmpmax;
1764
1796
int exitcode = EXIT_SUCCESS;
1765
char *interfaces = NULL;
1766
size_t interfaces_size = 0;
1767
1797
char *interfaces_to_take_down = NULL;
1768
1798
size_t interfaces_to_take_down_size = 0;
1769
1799
char tempdir[] = "/tmp/mandosXXXXXX";
1869
1899
connect_to = arg;
1871
1901
case 'i': /* --interface */
1872
ret_errno = argz_add_sep(&interfaces, &interfaces_size, arg,
1902
ret_errno = argz_add_sep(&mc.interfaces, &mc.interfaces_size,
1874
1904
if(ret_errno != 0){
1875
1905
argp_error(state, "%s", strerror(ret_errno));
2005
2035
/* Lower privileges */
2009
perror_plus("seteuid");
2014
/* Remove empty interface names */
2040
/* Remove invalid interface names (except "none") */
2016
2042
char *interface = NULL;
2017
while((interface = argz_next(interfaces, interfaces_size,
2043
while((interface = argz_next(mc.interfaces, mc.interfaces_size,
2019
if(if_nametoindex(interface) == 0){
2020
if(interface[0] != '\0' and strcmp(interface, "none") != 0){
2045
if(strcmp(interface, "none") != 0
2046
and if_nametoindex(interface) == 0){
2047
if(interface[0] != '\0'){
2021
2048
fprintf_plus(stderr, "Not using nonexisting interface"
2022
2049
" \"%s\"\n", interface);
2024
argz_delete(&interfaces, &interfaces_size, interface);
2051
argz_delete(&mc.interfaces, &mc.interfaces_size, interface);
2025
2052
interface = NULL;
2030
2057
/* Run network hooks */
2033
if(interfaces != NULL){
2034
interfaces_hooks = malloc(interfaces_size);
2059
if(mc.interfaces != NULL){
2060
interfaces_hooks = malloc(mc.interfaces_size);
2035
2061
if(interfaces_hooks == NULL){
2036
2062
perror_plus("malloc");
2039
memcpy(interfaces_hooks, interfaces, interfaces_size);
2040
interfaces_hooks_size = interfaces_size;
2065
memcpy(interfaces_hooks, mc.interfaces, mc.interfaces_size);
2066
interfaces_hooks_size = mc.interfaces_size;
2041
2067
argz_stringify(interfaces_hooks, interfaces_hooks_size,
2129
2155
/* If no interfaces were specified, make a list */
2130
if(interfaces == NULL){
2156
if(mc.interfaces == NULL){
2131
2157
struct dirent **direntries;
2132
2158
/* Look for any good interfaces */
2133
2159
ret = scandir(sys_class_net, &direntries, good_interface,
2136
2162
/* Add all found interfaces to interfaces list */
2137
2163
for(int i = 0; i < ret; ++i){
2138
ret_errno = argz_add(&interfaces, &interfaces_size,
2164
ret_errno = argz_add(&mc.interfaces, &mc.interfaces_size,
2139
2165
direntries[i]->d_name);
2140
2166
if(ret_errno != 0){
2141
2167
perror_plus("argz_add");
2158
/* If we only got one interface, explicitly use only that one */
2159
if(argz_count(interfaces, interfaces_size) == 1){
2161
fprintf_plus(stderr, "Using only interface \"%s\"\n",
2164
if_index = (AvahiIfIndex)if_nametoindex(interfaces);
2167
2184
/* Bring up interfaces which are down */
2168
if(not (argz_count(interfaces, interfaces_size) == 1
2169
and strcmp(interfaces, "none") == 0)){
2170
2186
char *interface = NULL;
2171
while((interface = argz_next(interfaces, interfaces_size,
2187
while((interface = argz_next(mc.interfaces, mc.interfaces_size,
2189
/* If interface name is "none", stop bringing up interfaces.
2190
Also remove all instances of "none" from the list */
2191
if(strcmp(interface, "none") == 0){
2192
argz_delete(&mc.interfaces, &mc.interfaces_size,
2195
while((interface = argz_next(mc.interfaces,
2196
mc.interfaces_size, interface))){
2197
if(strcmp(interface, "none") == 0){
2198
argz_delete(&mc.interfaces, &mc.interfaces_size,
2173
2205
bool interface_was_up = interface_is_up(interface);
2174
2206
ret = bring_up_interface(interface, delay);
2175
2207
if(not interface_was_up){
2188
interfaces_size = 0;
2189
2218
if(debug and (interfaces_to_take_down == NULL)){
2190
2219
fprintf_plus(stderr, "No interfaces were brought up\n");
2223
/* If we only got one interface, explicitly use only that one */
2224
if(argz_count(mc.interfaces, mc.interfaces_size) == 1){
2226
fprintf_plus(stderr, "Using only interface \"%s\"\n",
2229
if_index = (AvahiIfIndex)if_nametoindex(mc.interfaces);