fix -p, so we don't need to supply a pattern
[shallot.git] / src / error.c
blob8527cabb9c8dffeb3c0d554330301cbb5530c03d
1 // error handling for shallot
3 #include "error.h"
4 #include "globals.h"
5 #include "defines.h"
7 #include <stdio.h>
8 #include <stdlib.h>
10 // help - how to use this stuff
11 void usage(void) {
12 printf("Usage: shallot [-dmopv] [-f <file>] [-t count] [-x time] [-e limit] pattern\n"
13 " -d : Daemonize (requires -f)\n"
14 " -m : Monitor mode (incompatible with -f)\n"
15 " -o : Optimize RSA key size to improve SHA-1 hashing speed\n"
16 " -p : Print 'pattern' help and exit\n"
17 " -f <file> : Write output to <file>\n"
18 " -t count : Forces exactly count threads to be spawned\n"
19 " -x secs : Sets a limit on the maximum execution time. Has no effect without -m\n"
20 " -e limit : Manually define the limit for e\n"
21 "Version: %s\n", VERSION);
22 exit(X_WRONG_NUMARGS);
25 void pattern(void) {
26 printf("base32 alphabet allows letters [a-z] and digits [2-7]\n"
27 "pattern can be a POSIX-style regular expression, e.g.\n"
28 " xxx must contain 'xxx'\n"
29 " bar$ must end with 'bar'\n"
30 " ^foo must begin with 'foo'\n"
31 " b[a4]r may contain leetspeech ;)\n"
32 " ^ab|^cd must begin with 'ab' or 'cd'\n"
33 " [a-z]{16} must contain letters only, no digits\n"
34 " ^dusk.*dawn$ must begin with 'dusk' and end with 'dawn'\n");
35 exit(X_WRONG_NUMARGS);
38 // our big error handling/reporting function
39 void error(int32_t code) {
40 switch(code) {
41 case X_REGEX_COMPILE: {
42 fprintf(stderr, "ERROR: Bad pattern. Try again with something else!\n");
43 break;
46 case X_REGEX_INVALID: {
47 fprintf(stderr, "ERROR: Pattern cannot contain '-'.\n");
48 break;
51 case X_SGNL_INT_TERM: {
52 fprintf(stderr, "\nCaught SIGINT/SIGTERM after %"PRIu64" tries - exiting.\n",
53 loop);
54 break;
57 case X_YOURE_UNLUCKY: {
58 fprintf(stderr, "\nERROR: You happened to find a bad key - congrats.\n");
59 break;
62 case X_KEY_GEN_FAILS: {
63 fprintf(stderr, "ERROR: RSA Key Generation failed. This is bad.\n");
64 break;
67 case X_THREAD_CREATE: {
68 fprintf(stderr, "ERROR: Failed to create thread. Terminating...\n");
69 break;
72 case X_BIGNUM_FAILED: {
73 fprintf(stderr, "ERROR: Failed to covert uint64_t to BIGNUM.\n");
74 break;
77 case X_INVALID_THRDS: {
78 fprintf(stderr, "ERROR: Invalid number of threads\n");
79 break;
82 case X_EXCLUSIVE_OPT: {
83 fprintf(stderr, "ERROR: -m is incompatible with -f/-v\n");
84 break;
87 case X_INVALID_E_LIM: {
88 fprintf(stderr, "ERROR: e limit must be odd, >= %llu, and <= %llu\n",
89 RSA_PK_EXPONENT, MAXIMUM_E_LIMIT);
90 break;
93 case X_NEED_FILE_OUT: {
94 fprintf(stderr, "ERROR: -d requires -f <file>\n");
95 break;
98 case X_FILE_OPEN_ERR: {
99 fprintf(stderr, "ERROR: Couldn't open file for output\n");
100 break;
103 case X_DAEMON_FAILED: {
104 fprintf(stderr, "ERROR: Daemonization failed\n");
105 break;
108 case X_OUT_OF_MEMORY: {
109 fprintf(stderr, "ERROR: Out of memory error.\n");
110 break;
112 case X_MAXTIME_REACH: {
113 fprintf(stderr,"\n%s\n","Maximum execution time reached; exiting...");
114 break;
118 #ifdef BSD
119 case X_SYSCTL_FAILED: {
120 fprintf(stderr, "ERROR: sysctlbyname failed.\n");
121 break;
124 #elif defined(LINUX_PORT)
125 case X_BAD_FILE_DESC: {
126 fprintf(stderr, "ERROR: Couldn't open processor information.\n");
127 break;
130 case X_ABNORMAL_READ: {
131 fprintf(stderr, "ERROR: Failed reading processor information.\n");
132 break;
134 #endif
136 default: {
137 fprintf(stderr, "Generic error. You should never see this...\n");
138 break;
140 } // end switch
142 exit(code);