00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
#include "spfquery.h"
00054
00055 int main(
int argc,
char *argv[])
00056 {
00057
int c;
00058
int res;
00059
00060
char *opt_file = NULL;
00061
char *opt_ipv4 = NULL;
00062
char *opt_sender = NULL;
00063
char *opt_helo = NULL;
00064
char *opt_rcpt_to = NULL;
00065
char *opt_local = NULL;
00066
char *opt_trusted = NULL;
00067
char *opt_guess = NULL;
00068
char *opt_exp = NULL;
00069
char *opt_max_lookup = NULL;
00070
char *opt_sanitize = NULL;
00071
char *opt_debuglevel = NULL;
00072
char *opt_myhostname =
"spfquery";
00073
00074
char in_line[4096];
00075
char *p;
00076
00077
int dbg_level = 0;
00078
00079
peer_info_t *peer_info = NULL;
00080
00081 FILE *fin;
00082
00083
while (
TRUE)
00084 {
00085
int option_index = 0;
00086
00087
static struct option long_options[] =
00088 {
00089 {
"file", 1, 0,
'f' },
00090 {
"ipv4", 1, 0,
'i' },
00091 {
"sender", 1, 0,
's' },
00092 {
"helo", 1, 0,
'h' },
00093 {
"rcpt-to", 1, 0,
'r' },
00094 {
"local", 1, 0,
'l' },
00095 {
"trusted", 1, 0,
't' },
00096 {
"guess", 1, 0,
'g' },
00097 {
"default_explanation", 1, 0,
'e' },
00098 {
"max-lookup", 1, 0,
'm' },
00099 {
"sanitize", 1, 0,
'c' },
00100 {
"myhostname", 1, 0,
'n' },
00101 {
"verbose", 1, 0,
'v' },
00102 {
"help", 0, 0,
'?' },
00103 { 0, 0, 0, 0 }
00104 };
00105
00106 c = getopt_long (argc, argv,
"f:i:s:h:r:v:ltgemcn",
00107 long_options, &option_index);
00108
00109
if (c == -1)
00110 {
00111
break;
00112 }
00113
00114
00115
switch (c)
00116 {
00117
case '?':
00118
SPF_usage();
00119
return 1;
00120
break;
00121
case 'f':
00122 opt_file = optarg;
00123
break;
00124
case 'i':
00125 opt_ipv4 = optarg;
00126
break;
00127
case 's':
00128 opt_sender = optarg;
00129
break;
00130
case 'h':
00131 opt_helo = optarg;
00132
break;
00133
case 'r':
00134 opt_rcpt_to = optarg;
00135
break;
00136
case 'l':
00137 opt_local = optarg;
00138
break;
00139
case 't':
00140 opt_trusted = optarg;
00141
break;
00142
case 'g':
00143 opt_guess = optarg;
00144
break;
00145
case 'e':
00146 opt_exp = optarg;
00147
break;
00148
case 'm':
00149 opt_max_lookup = optarg;
00150
break;
00151
case 'c':
00152 opt_sanitize = optarg;
00153
break;
00154
case 'n':
00155 opt_myhostname = optarg;
00156
break;
00157
case 'v':
00158 opt_debuglevel = optarg;
00159 dbg_level = atoi(opt_debuglevel);
00160
confg.
level = dbg_level;
00161 fprintf(stderr,
"DEBUGGING LEVEL IS: %i\n", dbg_level);
00162
break;
00163
default:
00164 fprintf(stderr,
"Error: getopt returned character code 0%o ??\n", c);
00165 }
00166 }
00167
00168
if (optind != argc)
00169 {
00170
SPF_usage();
00171
return 1;
00172 }
00173
00174
00175
if (opt_ipv4 == NULL || opt_sender == NULL || opt_helo == NULL)
00176 {
00177
if (opt_file == NULL || opt_ipv4 != NULL || opt_sender != NULL ||
00178 opt_helo != NULL)
00179 {
00180
SPF_usage();
00181
return TRUE;
00182 }
00183
00184
00185
if (strcmp(opt_file,
"-" ) == 0)
00186 {
00187 fin = stdin;
00188 }
00189
else
00190 {
00191 fin = fopen(opt_file,
"r");
00192 }
00193
00194
if (!fin)
00195 {
00196 fprintf(stderr,
"Could not open: %s\n", opt_file);
00197
return 1;
00198 }
00199
00200
while (
TRUE )
00201 {
00202
if (fgets(in_line,
sizeof(in_line), stdin) == NULL)
00203 {
00204
break;
00205 }
00206
00207 p = strchr(in_line,
'\n');
00208
00209
if (p != NULL)
00210 {
00211 *p =
'\0';
00212 }
00213
00214 p = in_line;
00215
00216
while ((opt_ipv4 = strsep(&p,
" \t\n")) != NULL && *opt_ipv4 ==
'\0')
00217 {
00218 ;
00219 }
00220
00221
if (opt_ipv4 == NULL)
00222 {
00223
break;
00224 }
00225
00226
while ((opt_sender = strsep(&p,
"\t\n")) != NULL && *opt_ipv4 ==
'\0')
00227 {
00228 ;
00229 }
00230
00231
while ((opt_helo = strsep(&p,
"\t\n")) != NULL && *opt_ipv4 ==
'\0')
00232 {
00233 ;
00234 }
00235
00236
if (dbg_level >= 1)
00237 {
00238 printf (
"ipv4: %s\n", opt_ipv4);
00239 printf (
"sender: %s\n", opt_sender);
00240 printf (
"helo: %s\n", opt_helo);
00241 }
00242
00243
if (peer_info == NULL)
00244 {
00245 peer_info =
SPF_init(opt_myhostname,
00246 opt_ipv4, NULL,
00247 opt_trusted ? opt_trusted : NULL,
00248 NULL,
00249 opt_trusted ?
TRUE :
FALSE,
00250
FALSE);
00251 }
00252
00253
if (opt_helo != NULL)
00254 {
00255
SPF_smtp_helo(peer_info, opt_helo);
00256 }
00257
00258
if (opt_sender != NULL)
00259 {
00260
SPF_smtp_from(peer_info, opt_sender);
00261 }
00262
00263 peer_info->
RES =
SPF_policy_main(peer_info);
00264 res = peer_info->
RES;
00265
00266 printf(
"%s\n%s\n%s\n", peer_info->
rs, peer_info->
error,
00267 peer_info->
explain);
00268
00269
SPF_close(peer_info);
00270 }
00271 }
00272
else
00273 {
00274
if (opt_file != NULL)
00275 {
00276
SPF_usage();
00277
return 1;
00278 }
00279
00280
00281
if ( dbg_level )
00282 {
00283 printf (
"ipv4: %s\n", opt_ipv4);
00284 printf (
"sender: %s\n", opt_sender);
00285 printf (
"helo: %s\n", opt_helo);
00286 }
00287
00288
if (peer_info == NULL)
00289 {
00290 peer_info =
SPF_init(opt_myhostname,
00291 opt_ipv4, NULL,
00292 opt_trusted ? opt_trusted : NULL,
00293 NULL,
00294 opt_trusted ?
TRUE :
FALSE,
00295
FALSE);
00296 }
00297
00298
if (opt_helo != NULL)
00299 {
00300
SPF_smtp_helo(peer_info, opt_helo);
00301 }
00302
00303
if (opt_sender != NULL)
00304 {
00305
SPF_smtp_from(peer_info, opt_sender);
00306 }
00307
00308 peer_info->
RES =
SPF_policy_main(peer_info);
00309
00310 printf(
"%s\n%s\n%s\n", peer_info->
rs, peer_info->
error,
00311 peer_info->
explain);
00312
00313 res = peer_info->
RES;
00314
SPF_close(peer_info);
00315
00316
return res;
00317 }
00318
00319
return FALSE;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 void SPF_usage()
00336 {
00337 fprintf(stderr,
"Usage:\n");
00338 fprintf(stderr,
"\n");
00339 fprintf(stderr,
"spfquery [-v] [-f <file>|spf data options]\n");
00340 fprintf(stderr,
"\n");
00341 fprintf(stderr,
"spfquery -i <IP Address> -s <email address> -h domain\n");
00342 fprintf(stderr,
"\n");
00343 fprintf(stderr,
"spfquery -i 10.0.0.2 -s jcouzens@6o4.ca -h spftools.net\n");
00344
00345
return;
00346 }
00347
00348