/mandos/trunk

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

« back to all changes in this revision

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

  • Committer: Teddy Hogeborn
  • Date: 2015-07-06 20:09:47 UTC
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: teddy@recompile.se-20150706200947-w21u4eq74efgl6r5
Fix minor bugs and typos and add some more debug output.

* Makefile (install-client-nokey): Create plugin-helpers directory and
                                   the mandos-client-iprouteadddel
                                   helper program.
* initramfs-tools-hook (PLUGINHELPERDIR): Fix typo.
* plugins.d/mandos-client.c: Change terminology; routes are "deleted",
                             not "removed".  All occurences changed.
  (add_remove_local_route): Renamed to "add_delete_local_route".  All
                            callers changed.  Also pass "--debug" flag
                            to helper if in debug mode.
  (add_local_route): Add debugging output.
  (remove_local_route): Renamed to "delete_local_route".  All callers
                        changed.  Also pass "--debug" flag to helper
                        if in debug mode.
  (start_mandos_communication): Add debug output when adding route.

Show diffs side-by-side

added added

removed removed

Lines of Context:
702
702
  return ret_errno;
703
703
}
704
704
 
705
 
/* Helper function to add_local_route() and remove_local_route() */
 
705
/* Helper function to add_local_route() and delete_local_route() */
706
706
__attribute__((nonnull, warn_unused_result))
707
 
static bool add_remove_local_route(const bool add,
 
707
static bool add_delete_local_route(const bool add,
708
708
                                   const char *address,
709
709
                                   AvahiIfIndex if_index){
710
710
  int ret;
711
711
  char helper[] = "mandos-client-iprouteadddel";
712
712
  char add_arg[] = "add";
713
713
  char delete_arg[] = "delete";
 
714
  char debug_flag[] = "--debug";
714
715
  char *pluginhelperdir = getenv("MANDOSPLUGINHELPERDIR");
715
716
  if(pluginhelperdir == NULL){
716
717
    if(debug){
792
793
#endif
793
794
    if(fexecve(helper_fd, (char *const [])
794
795
               { helper, add ? add_arg : delete_arg, (char *)address,
795
 
                   interface, NULL }, environ) == -1){
 
796
                   interface, debug ? debug_flag : NULL, NULL },
 
797
               environ) == -1){
796
798
#ifdef __GNUC__
797
799
#pragma GCC diagnostic pop
798
800
#endif
850
852
__attribute__((nonnull, warn_unused_result))
851
853
static bool add_local_route(const char *address,
852
854
                            AvahiIfIndex if_index){
853
 
  return add_remove_local_route(true, address, if_index);
 
855
  if(debug){
 
856
    fprintf_plus(stderr, "Adding route to %s\n", address);
 
857
  }
 
858
  return add_delete_local_route(true, address, if_index);
854
859
}
855
860
 
856
861
__attribute__((nonnull, warn_unused_result))
857
 
static bool remove_local_route(const char *address,
 
862
static bool delete_local_route(const char *address,
858
863
                               AvahiIfIndex if_index){
859
 
  return add_remove_local_route(false, address, if_index);
 
864
  if(debug){
 
865
    fprintf_plus(stderr, "Removing route to %s\n", address);
 
866
  }
 
867
  return add_delete_local_route(false, address, if_index);
860
868
}
861
869
 
862
870
/* Called when a Mandos server is found */
1065
1073
           http://lists.freedesktop.org/archives/avahi/2010-February/001833.html
1066
1074
           https://bugs.debian.org/587961
1067
1075
        */
 
1076
        if(debug){
 
1077
          fprintf_plus(stderr, "Mandos server unreachable, trying"
 
1078
                       " direct route\n");
 
1079
        }
1068
1080
        int e = errno;
1069
1081
        route_added = add_local_route(ip, if_index);
1070
1082
        if(route_added){
1274
1286
 mandos_end:
1275
1287
  {
1276
1288
    if(route_added){
1277
 
      if(not remove_local_route(ip, if_index)){
1278
 
        fprintf_plus(stderr, "Failed to remove local route to %s on"
 
1289
      if(not delete_local_route(ip, if_index)){
 
1290
        fprintf_plus(stderr, "Failed to delete local route to %s on"
1279
1291
                     " interface %d", ip, if_index);
1280
1292
      }
1281
1293
    }