Explorar el Código

Fixing exit-codes: -1 in case no attack was found, 0 if found, > 0 otherwise.

Exit-code statuses are now advised by qa_dispose(), which has direct control
with the various questions and can immediately return if anything fails, ot
either if a key was found.
Michele Orrù hace 11 años
padre
commit
5f300a0450
Se han modificado 2 ficheros con 8 adiciones y 6 borrados
  1. 0 2
      src/include/qa/qa.h
  2. 8 4
      src/qa.c

+ 0 - 2
src/include/qa/qa.h

@@ -14,8 +14,6 @@ struct qa_conf {
 
 int qa_init(const struct qa_conf* args);
 
-void qa_dispose(X509 *crt, RSA *rsa);
-
 X509* get_local_cert(const char *src);
 
 #endif   /* _QA_H_ */

+ 8 - 4
src/qa.c

@@ -23,6 +23,8 @@
 #include "qa/questions/questions.h"
 #include "qa/qa_sock.h"
 
+static int qa_dispose(X509 *crt, RSA *rsa);
+
 /**
  * \Handle unexpected error.
  *
@@ -114,6 +116,7 @@ print_rsa_private(RSA *rsa)
 int
 qa_init(const struct qa_conf* conf)
 {
+  int exitcode;
   X509 *crt = NULL;
   RSA *rsa = NULL;
 
@@ -142,13 +145,13 @@ qa_init(const struct qa_conf* conf)
 
   if (!questions.lh_first) error(EXIT_FAILURE, 0, "No valid question selected.");
 
-  qa_dispose(crt, rsa);
+  exitcode = qa_dispose(crt, rsa);
 
   X509_free(crt);
-  return 0;
+  return exitcode;
 }
 
-void
+static int
 qa_dispose(X509 *crt, RSA *rsa)
 {
   RSA *pub;
@@ -188,6 +191,7 @@ qa_dispose(X509 *crt, RSA *rsa)
         (priv = q->ask_rsa(pub))) {
       fprintf(stderr, "[\\] Key Broken using %s.\n", q->pretty_name);
       print_rsa_private(priv);
+      return EXIT_SUCCESS;
     }
 
     /*
@@ -208,5 +212,5 @@ qa_dispose(X509 *crt, RSA *rsa)
   /*
    *  Key seems resistent: exit with status -1
    */
-  exit(-1);
+  return -1;
 }