diff options
Diffstat (limited to 'plugins-root')
| -rw-r--r-- | plugins-root/check_dhcp.c | 56 | ||||
| -rw-r--r-- | plugins-root/pst3.c | 4 |
2 files changed, 18 insertions, 42 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c index 3723e61a..88b7ca10 100644 --- a/plugins-root/check_dhcp.c +++ b/plugins-root/check_dhcp.c | |||
| @@ -229,7 +229,7 @@ struct in_addr requested_address; | |||
| 229 | 229 | ||
| 230 | int process_arguments(int, char **); | 230 | int process_arguments(int, char **); |
| 231 | int call_getopt(int, char **); | 231 | int call_getopt(int, char **); |
| 232 | int validate_arguments(void); | 232 | int validate_arguments(int, int); |
| 233 | void print_usage(void); | 233 | void print_usage(void); |
| 234 | void print_help(void); | 234 | void print_help(void); |
| 235 | 235 | ||
| @@ -463,10 +463,9 @@ int send_dhcp_discover(int sock){ | |||
| 463 | discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; | 463 | discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; |
| 464 | 464 | ||
| 465 | /* | 465 | /* |
| 466 | * transaction ID is supposed to be random. We won't use the address so | 466 | * transaction ID is supposed to be random. |
| 467 | * we don't care about high entropy here. time(2) is good enough. | ||
| 468 | */ | 467 | */ |
| 469 | srand(time(NULL)); | 468 | srand(time(NULL)^getpid()); |
| 470 | packet_xid=random(); | 469 | packet_xid=random(); |
| 471 | discover_packet.xid=htonl(packet_xid); | 470 | discover_packet.xid=htonl(packet_xid); |
| 472 | 471 | ||
| @@ -692,17 +691,11 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st | |||
| 692 | } | 691 | } |
| 693 | 692 | ||
| 694 | else{ | 693 | else{ |
| 695 | |||
| 696 | /* why do we need to peek first? i don't know, its a hack. without it, the source address of the first packet received was | ||
| 697 | not being interpreted correctly. sigh... */ | ||
| 698 | bzero(&source_address,sizeof(source_address)); | 694 | bzero(&source_address,sizeof(source_address)); |
| 699 | address_size=sizeof(source_address); | 695 | address_size=sizeof(source_address); |
| 700 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size); | 696 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size); |
| 701 | if(verbose) | 697 | if(verbose) |
| 702 | printf("recv_result_1: %d\n",recv_result); | 698 | printf("recv_result: %d\n",recv_result); |
| 703 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size); | ||
| 704 | if(verbose) | ||
| 705 | printf("recv_result_2: %d\n",recv_result); | ||
| 706 | 699 | ||
| 707 | if(recv_result==-1){ | 700 | if(recv_result==-1){ |
| 708 | if(verbose){ | 701 | if(verbose){ |
| @@ -1059,29 +1052,19 @@ int get_results(void){ | |||
| 1059 | 1052 | ||
| 1060 | /* process command-line arguments */ | 1053 | /* process command-line arguments */ |
| 1061 | int process_arguments(int argc, char **argv){ | 1054 | int process_arguments(int argc, char **argv){ |
| 1062 | int c; | 1055 | int arg_index; |
| 1063 | 1056 | ||
| 1064 | if(argc<1) | 1057 | if(argc<1) |
| 1065 | return ERROR; | 1058 | return ERROR; |
| 1066 | 1059 | ||
| 1067 | c=0; | 1060 | arg_index = call_getopt(argc,argv); |
| 1068 | while((c+=(call_getopt(argc-c,&argv[c])))<argc){ | 1061 | return validate_arguments(argc,arg_index); |
| 1069 | |||
| 1070 | /* | ||
| 1071 | if(is_option(argv[c])) | ||
| 1072 | continue; | ||
| 1073 | */ | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | return validate_arguments(); | ||
| 1077 | } | 1062 | } |
| 1078 | 1063 | ||
| 1079 | 1064 | ||
| 1080 | 1065 | ||
| 1081 | int call_getopt(int argc, char **argv){ | 1066 | int call_getopt(int argc, char **argv){ |
| 1082 | int c=0; | 1067 | extern int optind; |
| 1083 | int i=0; | ||
| 1084 | |||
| 1085 | int option_index = 0; | 1068 | int option_index = 0; |
| 1086 | static struct option long_options[] = | 1069 | static struct option long_options[] = |
| 1087 | { | 1070 | { |
| @@ -1098,25 +1081,14 @@ int call_getopt(int argc, char **argv){ | |||
| 1098 | }; | 1081 | }; |
| 1099 | 1082 | ||
| 1100 | while(1){ | 1083 | while(1){ |
| 1101 | c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index); | 1084 | int c=0; |
| 1102 | 1085 | ||
| 1103 | i++; | 1086 | c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index); |
| 1104 | 1087 | ||
| 1105 | if(c==-1||c==EOF||c==1) | 1088 | if(c==-1||c==EOF||c==1) |
| 1106 | break; | 1089 | break; |
| 1107 | 1090 | ||
| 1108 | switch(c){ | 1091 | switch(c){ |
| 1109 | case 'w': | ||
| 1110 | case 'r': | ||
| 1111 | case 't': | ||
| 1112 | case 'i': | ||
| 1113 | i++; | ||
| 1114 | break; | ||
| 1115 | default: | ||
| 1116 | break; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | switch(c){ | ||
| 1120 | 1092 | ||
| 1121 | case 's': /* DHCP server address */ | 1093 | case 's': /* DHCP server address */ |
| 1122 | resolve_host(optarg,&dhcp_ip); | 1094 | resolve_host(optarg,&dhcp_ip); |
| @@ -1181,12 +1153,14 @@ int call_getopt(int argc, char **argv){ | |||
| 1181 | break; | 1153 | break; |
| 1182 | } | 1154 | } |
| 1183 | } | 1155 | } |
| 1184 | 1156 | return optind; | |
| 1185 | return i; | ||
| 1186 | } | 1157 | } |
| 1187 | 1158 | ||
| 1188 | 1159 | ||
| 1189 | int validate_arguments(void){ | 1160 | int validate_arguments(int argc, int arg_index){ |
| 1161 | |||
| 1162 | if(argc-optind > 0) | ||
| 1163 | usage(_("Got unexpected non-option argument")); | ||
| 1190 | 1164 | ||
| 1191 | return OK; | 1165 | return OK; |
| 1192 | } | 1166 | } |
diff --git a/plugins-root/pst3.c b/plugins-root/pst3.c index ee9d108d..c3589f0a 100644 --- a/plugins-root/pst3.c +++ b/plugins-root/pst3.c | |||
| @@ -139,8 +139,10 @@ try_again: | |||
| 139 | if((ps_fd = open(ps_name, O_RDONLY)) == -1) | 139 | if((ps_fd = open(ps_name, O_RDONLY)) == -1) |
| 140 | continue; | 140 | continue; |
| 141 | 141 | ||
| 142 | if((as_fd = open(as_name, O_RDONLY)) == -1) | 142 | if((as_fd = open(as_name, O_RDONLY)) == -1) { |
| 143 | close(ps_fd); | ||
| 143 | continue; | 144 | continue; |
| 145 | } | ||
| 144 | 146 | ||
| 145 | if(read(ps_fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) { | 147 | if(read(ps_fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) { |
| 146 | int err = errno; | 148 | int err = errno; |
