/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2012-06-16 23:39:10 UTC
  • mto: (301.1.1 release) (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 302.
  • Revision ID: teddy@recompile.se-20120616233910-jxxxriq608qa6o8z
* plugins.d/mandos-client (mandos_context): New "interfaces" and
                                            "interfaces_size" members.
  (main): Removed "interfaces" and "interfaces_size" variabled; all
          users changed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
11
 * Everything else is
12
 
 * Copyright © 2008-2013 Teddy Hogeborn
13
 
 * Copyright © 2008-2013 Björn Påhlsson
 
12
 * Copyright © 2008-2012 Teddy Hogeborn
 
13
 * Copyright © 2008-2012 Björn Påhlsson
14
14
 * 
15
15
 * This program is free software: you can redistribute it and/or
16
16
 * modify it under the terms of the GNU General Public License as
187
187
  
188
188
  TEMP_FAILURE_RETRY(fprintf(stream, "Mandos plugin %s: ",
189
189
                             program_invocation_short_name));
190
 
  return (int)TEMP_FAILURE_RETRY(vfprintf(stream, format, ap));
 
190
  return TEMP_FAILURE_RETRY(vfprintf(stream, format, ap));
191
191
}
192
192
 
193
193
/*
659
659
    return -1;
660
660
  }
661
661
  
662
 
  /* If the interface is specified and we have a list of interfaces */
663
 
  if(if_index != AVAHI_IF_UNSPEC and mc->interfaces != NULL){
664
 
    /* Check if the interface is one of the interfaces we are using */
665
 
    bool match = false;
666
 
    {
667
 
      char *interface = NULL;
668
 
      while((interface=argz_next(mc->interfaces, mc->interfaces_size,
669
 
                                 interface))){
670
 
        if(if_nametoindex(interface) == (unsigned int)if_index){
671
 
          match = true;
672
 
          break;
673
 
        }
674
 
      }
675
 
    }
676
 
    if(not match){
677
 
      /* This interface does not match any in the list, so we don't
678
 
         connect to the server */
679
 
      if(debug){
680
 
        char interface[IF_NAMESIZE];
681
 
        if(if_indextoname((unsigned int)if_index, interface) == NULL){
682
 
          perror_plus("if_indextoname");
683
 
        } else {
684
 
          fprintf_plus(stderr, "Skipping server on non-used interface"
685
 
                       " \"%s\"\n",
686
 
                       if_indextoname((unsigned int)if_index,
687
 
                                      interface));
688
 
        }
689
 
      }
690
 
      return -1;
691
 
    }
692
 
  }
693
 
  
694
662
  ret = init_gnutls_session(&session, mc);
695
663
  if(ret != 0){
696
664
    return -1;
2036
2004
      }
2037
2005
    
2038
2006
      /* Lower privileges */
2039
 
      lower_privileges();
 
2007
      errno = 0;
 
2008
      ret = seteuid(uid);
 
2009
      if(ret == -1){
 
2010
        perror_plus("seteuid");
 
2011
      }
2040
2012
    }
2041
2013
  }
2042
2014
  
2043
 
  /* Remove invalid interface names (except "none") */
 
2015
  /* Remove empty interface names */
2044
2016
  {
2045
2017
    char *interface = NULL;
2046
2018
    while((interface = argz_next(mc.interfaces, mc.interfaces_size,
2047
2019
                                 interface))){
2048
 
      if(strcmp(interface, "none") != 0
2049
 
         and if_nametoindex(interface) == 0){
2050
 
        if(interface[0] != '\0'){
 
2020
      if(if_nametoindex(interface) == 0){
 
2021
        if(interface[0] != '\0' and strcmp(interface, "none") != 0){
2051
2022
          fprintf_plus(stderr, "Not using nonexisting interface"
2052
2023
                       " \"%s\"\n", interface);
2053
2024
        }
2059
2030
  
2060
2031
  /* Run network hooks */
2061
2032
  {
 
2033
    
2062
2034
    if(mc.interfaces != NULL){
2063
2035
      interfaces_hooks = malloc(mc.interfaces_size);
2064
2036
      if(interfaces_hooks == NULL){
2184
2156
    }
2185
2157
  }
2186
2158
  
2187
 
  /* Bring up interfaces which are down, and remove any "none"s */
2188
 
  {
 
2159
  /* If we only got one interface, explicitly use only that one */
 
2160
  if(argz_count(mc.interfaces, mc.interfaces_size) == 1){
 
2161
    if(debug){
 
2162
      fprintf_plus(stderr, "Using only interface \"%s\"\n",
 
2163
                   mc.interfaces);
 
2164
    }
 
2165
    if_index = (AvahiIfIndex)if_nametoindex(mc.interfaces);
 
2166
  }
 
2167
  
 
2168
  /* Bring up interfaces which are down */
 
2169
  if(not (argz_count(mc.interfaces, mc.interfaces_size) == 1
 
2170
          and strcmp(mc.interfaces, "none") == 0)){
2189
2171
    char *interface = NULL;
2190
2172
    while((interface = argz_next(mc.interfaces, mc.interfaces_size,
2191
2173
                                 interface))){
2192
 
      /* If interface name is "none", stop bringing up interfaces.
2193
 
         Also remove all instances of "none" from the list */
2194
 
      if(strcmp(interface, "none") == 0){
2195
 
        argz_delete(&mc.interfaces, &mc.interfaces_size,
2196
 
                    interface);
2197
 
        interface = NULL;
2198
 
        while((interface = argz_next(mc.interfaces,
2199
 
                                     mc.interfaces_size, interface))){
2200
 
          if(strcmp(interface, "none") == 0){
2201
 
            argz_delete(&mc.interfaces, &mc.interfaces_size,
2202
 
                        interface);
2203
 
            interface = NULL;
2204
 
          }
2205
 
        }
2206
 
        break;
2207
 
      }
2208
2174
      bool interface_was_up = interface_is_up(interface);
2209
2175
      ret = bring_up_interface(interface, delay);
2210
2176
      if(not interface_was_up){
2218
2184
        }
2219
2185
      }
2220
2186
    }
 
2187
    free(mc.interfaces);
 
2188
    mc.interfaces = NULL;
 
2189
    mc.interfaces_size = 0;
2221
2190
    if(debug and (interfaces_to_take_down == NULL)){
2222
2191
      fprintf_plus(stderr, "No interfaces were brought up\n");
2223
2192
    }
2224
2193
  }
2225
2194
  
2226
 
  /* If we only got one interface, explicitly use only that one */
2227
 
  if(argz_count(mc.interfaces, mc.interfaces_size) == 1){
2228
 
    if(debug){
2229
 
      fprintf_plus(stderr, "Using only interface \"%s\"\n",
2230
 
                   mc.interfaces);
2231
 
    }
2232
 
    if_index = (AvahiIfIndex)if_nametoindex(mc.interfaces);
2233
 
  }
2234
 
  
2235
2195
  if(quit_now){
2236
2196
    goto end;
2237
2197
  }
2295
2255
      exitcode = EX_USAGE;
2296
2256
      goto end;
2297
2257
    }
2298
 
    
 
2258
  
2299
2259
    if(quit_now){
2300
2260
      goto end;
2301
2261
    }
2331
2291
        fprintf_plus(stderr, "Retrying in %d seconds\n",
2332
2292
                     (int)retry_interval);
2333
2293
      }
2334
 
      sleep((unsigned int)retry_interval);
 
2294
      sleep((int)retry_interval);
2335
2295
    }
2336
2296
    
2337
2297
    if (not quit_now){
2410
2370
  }
2411
2371
  
2412
2372
  /* Cleanup things */
2413
 
  free(mc.interfaces);
2414
 
  
2415
2373
  if(sb != NULL)
2416
2374
    avahi_s_service_browser_free(sb);
2417
2375