Back to index

lightning-sunbird  0.9+nobinonly
Defines | Enumerations | Functions | Variables
signtool.c File Reference
#include "nss.h"
#include "signtool.h"
#include "prmem.h"
#include "prio.h"

Go to the source code of this file.

Defines

#define CMD_FILE_BUFSIZE   1024

Enumerations

enum  OPT_TYPE {
  UNKNOWN_OPT, QUESTION_OPT, BASE_OPT, COMPRESSION_OPT,
  CERT_DIR_OPT, EXTENSION_OPT, INSTALL_SCRIPT_OPT, SCRIPTDIR_OPT,
  CERTNAME_OPT, LIST_OBJSIGN_CERTS_OPT, LIST_ALL_CERTS_OPT, METAFILE_OPT,
  OPTIMIZE_OPT, ENABLE_OCSP_OPT, PASSWORD_OPT, VERIFY_OPT,
  WHO_OPT, EXCLUDE_OPT, NO_TIME_OPT, JAVASCRIPT_OPT,
  ZIPFILE_OPT, GENKEY_OPT, MODULES_OPT, NORECURSE_OPT,
  SIGNDIR_OPT, OUTFILE_OPT, COMMAND_FILE_OPT, LEAVE_ARC_OPT,
  VERBOSITY_OPT, KEYSIZE_OPT, TOKEN_OPT, XPI_ARC_OPT,
  UNKNOWN_OPT, QUESTION_OPT, BASE_OPT, COMPRESSION_OPT,
  CERT_DIR_OPT, EXTENSION_OPT, INSTALL_SCRIPT_OPT, SCRIPTDIR_OPT,
  CERTNAME_OPT, LIST_OBJSIGN_CERTS_OPT, LIST_ALL_CERTS_OPT, METAFILE_OPT,
  OPTIMIZE_OPT, ENABLE_OCSP_OPT, PASSWORD_OPT, VERIFY_OPT,
  WHO_OPT, EXCLUDE_OPT, NO_TIME_OPT, JAVASCRIPT_OPT,
  ZIPFILE_OPT, GENKEY_OPT, MODULES_OPT, NORECURSE_OPT,
  SIGNDIR_OPT, OUTFILE_OPT, COMMAND_FILE_OPT, LEAVE_ARC_OPT,
  VERBOSITY_OPT, KEYSIZE_OPT, TOKEN_OPT, XPI_ARC_OPT
}
enum  Error {
  NO_ERR = 0, INVALID_USAGE_ERR, UNEXPECTED_ARG_ERR, UNKNOWN_OPTION_ERR,
  MULTIPLE_COMMAND_ERR, OPTION_NEEDS_ARG_ERR, DUPLICATE_OPTION_ERR, MISSING_PARAM_ERR,
  INVALID_FIPS_ARG, NO_COMMAND_ERR, NO_DBDIR_ERR, FIPS_SWITCH_FAILED_ERR,
  FIPS_ALREADY_ON_ERR, FIPS_ALREADY_OFF_ERR, FILE_ALREADY_EXISTS_ERR, FILE_DOESNT_EXIST_ERR,
  FILE_NOT_READABLE_ERR, FILE_NOT_WRITEABLE_ERR, DIR_DOESNT_EXIST_ERR, DIR_NOT_READABLE_ERR,
  DIR_NOT_WRITEABLE_ERR, INVALID_CONSTANT_ERR, ADD_MODULE_FAILED_ERR, ADD_MODULE_FAILED_STATUS_ERR,
  OUT_OF_MEM_ERR, DELETE_INTERNAL_ERR, DELETE_FAILED_ERR, NO_LIST_LOCK_ERR,
  NO_MODULE_LIST_ERR, NO_SUCH_MODULE_ERR, MOD_INFO_ERR, SLOT_INFO_ERR,
  TOKEN_INFO_ERR, NO_SUCH_TOKEN_ERR, CHANGEPW_FAILED_ERR, BAD_PW_ERR,
  DB_ACCESS_ERR, AUTHENTICATION_FAILED_ERR, NO_SUCH_SLOT_ERR, ENABLE_FAILED_ERR,
  UPDATE_MOD_FAILED_ERR, DEFAULT_FAILED_ERR, UNDEFAULT_FAILED_ERR, STDIN_READ_ERR,
  UNSPECIFIED_ERR, NOCERTDB_MISUSE_ERR, NSS_INITIALIZE_FAILED_ERR, LAST_ERR,
  DUPLICATE_OPTION_ERR = 0, OPTION_NEEDS_ARG_ERR, NO_ERR = 0, INVALID_USAGE_ERR,
  UNEXPECTED_ARG_ERR, UNKNOWN_OPTION_ERR, MULTIPLE_COMMAND_ERR, OPTION_NEEDS_ARG_ERR,
  DUPLICATE_OPTION_ERR, MISSING_PARAM_ERR, INVALID_FIPS_ARG, NO_COMMAND_ERR,
  NO_DBDIR_ERR, FIPS_SWITCH_FAILED_ERR, FIPS_ALREADY_ON_ERR, FIPS_ALREADY_OFF_ERR,
  FILE_ALREADY_EXISTS_ERR, FILE_DOESNT_EXIST_ERR, FILE_NOT_READABLE_ERR, FILE_NOT_WRITEABLE_ERR,
  DIR_DOESNT_EXIST_ERR, DIR_NOT_READABLE_ERR, DIR_NOT_WRITEABLE_ERR, INVALID_CONSTANT_ERR,
  ADD_MODULE_FAILED_ERR, ADD_MODULE_FAILED_STATUS_ERR, OUT_OF_MEM_ERR, DELETE_INTERNAL_ERR,
  DELETE_FAILED_ERR, NO_LIST_LOCK_ERR, NO_MODULE_LIST_ERR, NO_SUCH_MODULE_ERR,
  MOD_INFO_ERR, SLOT_INFO_ERR, TOKEN_INFO_ERR, NO_SUCH_TOKEN_ERR,
  CHANGEPW_FAILED_ERR, BAD_PW_ERR, DB_ACCESS_ERR, AUTHENTICATION_FAILED_ERR,
  NO_SUCH_SLOT_ERR, ENABLE_FAILED_ERR, UPDATE_MOD_FAILED_ERR, DEFAULT_FAILED_ERR,
  UNDEFAULT_FAILED_ERR, STDIN_READ_ERR, UNSPECIFIED_ERR, NOCERTDB_MISUSE_ERR,
  NSS_INITIALIZE_FAILED_ERR, LAST_ERR, DUPLICATE_OPTION_ERR = 0, OPTION_NEEDS_ARG_ERR
}

Functions

static int ProcessOneOpt (OPT_TYPE type, char *arg)
int ProcessCommandFile ()
static int parse_args (int argc, char *argv[])
int main (int argc, char *argv[])

Variables

char * progName
char * password = NULL
PLHashTableexcludeDirs = NULL
static PRBool exclusionsGiven = PR_FALSE
int no_time = 0
char * base = DEFAULT_BASE_NAME
PLHashTableextensions = NULL
PRBool extensionsGiven = PR_FALSE
char * scriptdir = NULL
int verbosity = 0
PRFileDescoutputFD = NULL
PRFileDescerrorFD = NULL
int errorCount = 0
int warningCount = 0
int compression_level = DEFAULT_COMPRESSION_LEVEL
PRBool compression_level_specified = PR_FALSE
int xpi_arc = 0
static char * genkey = NULL
static char * verify = NULL
static char * zipfile = NULL
static char * cert_dir = NULL
static int javascript = 0
static char * jartree = NULL
static char * keyName = NULL
static char * metafile = NULL
static char * install_script = NULL
static int list_certs = 0
static int list_modules = 0
static int optimize = 0
static int enableOCSP = 0
static char * tell_who = NULL
static char * outfile = NULL
static char * cmdFile = NULL
static PRBool noRecurse = PR_FALSE
static PRBool leaveArc = PR_FALSE
static int keySize = -1
static char * token = NULL
static char * errStrings []

Define Documentation


Enumeration Type Documentation

enum Error
Enumerator:
NO_ERR 
INVALID_USAGE_ERR 
UNEXPECTED_ARG_ERR 
UNKNOWN_OPTION_ERR 
MULTIPLE_COMMAND_ERR 
OPTION_NEEDS_ARG_ERR 
DUPLICATE_OPTION_ERR 
MISSING_PARAM_ERR 
INVALID_FIPS_ARG 
NO_COMMAND_ERR 
NO_DBDIR_ERR 
FIPS_SWITCH_FAILED_ERR 
FIPS_ALREADY_ON_ERR 
FIPS_ALREADY_OFF_ERR 
FILE_ALREADY_EXISTS_ERR 
FILE_DOESNT_EXIST_ERR 
FILE_NOT_READABLE_ERR 
FILE_NOT_WRITEABLE_ERR 
DIR_DOESNT_EXIST_ERR 
DIR_NOT_READABLE_ERR 
DIR_NOT_WRITEABLE_ERR 
INVALID_CONSTANT_ERR 
ADD_MODULE_FAILED_ERR 
ADD_MODULE_FAILED_STATUS_ERR 
OUT_OF_MEM_ERR 
DELETE_INTERNAL_ERR 
DELETE_FAILED_ERR 
NO_LIST_LOCK_ERR 
NO_MODULE_LIST_ERR 
NO_SUCH_MODULE_ERR 
MOD_INFO_ERR 
SLOT_INFO_ERR 
TOKEN_INFO_ERR 
NO_SUCH_TOKEN_ERR 
CHANGEPW_FAILED_ERR 
BAD_PW_ERR 
DB_ACCESS_ERR 
AUTHENTICATION_FAILED_ERR 
NO_SUCH_SLOT_ERR 
ENABLE_FAILED_ERR 
UPDATE_MOD_FAILED_ERR 
DEFAULT_FAILED_ERR 
UNDEFAULT_FAILED_ERR 
STDIN_READ_ERR 
UNSPECIFIED_ERR 
NOCERTDB_MISUSE_ERR 
NSS_INITIALIZE_FAILED_ERR 
LAST_ERR 
DUPLICATE_OPTION_ERR 
OPTION_NEEDS_ARG_ERR 
NO_ERR 
INVALID_USAGE_ERR 
UNEXPECTED_ARG_ERR 
UNKNOWN_OPTION_ERR 
MULTIPLE_COMMAND_ERR 
OPTION_NEEDS_ARG_ERR 
DUPLICATE_OPTION_ERR 
MISSING_PARAM_ERR 
INVALID_FIPS_ARG 
NO_COMMAND_ERR 
NO_DBDIR_ERR 
FIPS_SWITCH_FAILED_ERR 
FIPS_ALREADY_ON_ERR 
FIPS_ALREADY_OFF_ERR 
FILE_ALREADY_EXISTS_ERR 
FILE_DOESNT_EXIST_ERR 
FILE_NOT_READABLE_ERR 
FILE_NOT_WRITEABLE_ERR 
DIR_DOESNT_EXIST_ERR 
DIR_NOT_READABLE_ERR 
DIR_NOT_WRITEABLE_ERR 
INVALID_CONSTANT_ERR 
ADD_MODULE_FAILED_ERR 
ADD_MODULE_FAILED_STATUS_ERR 
OUT_OF_MEM_ERR 
DELETE_INTERNAL_ERR 
DELETE_FAILED_ERR 
NO_LIST_LOCK_ERR 
NO_MODULE_LIST_ERR 
NO_SUCH_MODULE_ERR 
MOD_INFO_ERR 
SLOT_INFO_ERR 
TOKEN_INFO_ERR 
NO_SUCH_TOKEN_ERR 
CHANGEPW_FAILED_ERR 
BAD_PW_ERR 
DB_ACCESS_ERR 
AUTHENTICATION_FAILED_ERR 
NO_SUCH_SLOT_ERR 
ENABLE_FAILED_ERR 
UPDATE_MOD_FAILED_ERR 
DEFAULT_FAILED_ERR 
UNDEFAULT_FAILED_ERR 
STDIN_READ_ERR 
UNSPECIFIED_ERR 
NOCERTDB_MISUSE_ERR 
NSS_INITIALIZE_FAILED_ERR 
LAST_ERR 
DUPLICATE_OPTION_ERR 
OPTION_NEEDS_ARG_ERR 

Definition at line 148 of file signtool.c.

enum OPT_TYPE
Enumerator:
UNKNOWN_OPT 
QUESTION_OPT 
BASE_OPT 
COMPRESSION_OPT 
CERT_DIR_OPT 
EXTENSION_OPT 
INSTALL_SCRIPT_OPT 
SCRIPTDIR_OPT 
CERTNAME_OPT 
LIST_OBJSIGN_CERTS_OPT 
LIST_ALL_CERTS_OPT 
METAFILE_OPT 
OPTIMIZE_OPT 
ENABLE_OCSP_OPT 
PASSWORD_OPT 
VERIFY_OPT 
WHO_OPT 
EXCLUDE_OPT 
NO_TIME_OPT 
JAVASCRIPT_OPT 
ZIPFILE_OPT 
GENKEY_OPT 
MODULES_OPT 
NORECURSE_OPT 
SIGNDIR_OPT 
OUTFILE_OPT 
COMMAND_FILE_OPT 
LEAVE_ARC_OPT 
VERBOSITY_OPT 
KEYSIZE_OPT 
TOKEN_OPT 
XPI_ARC_OPT 
UNKNOWN_OPT 
QUESTION_OPT 
BASE_OPT 
COMPRESSION_OPT 
CERT_DIR_OPT 
EXTENSION_OPT 
INSTALL_SCRIPT_OPT 
SCRIPTDIR_OPT 
CERTNAME_OPT 
LIST_OBJSIGN_CERTS_OPT 
LIST_ALL_CERTS_OPT 
METAFILE_OPT 
OPTIMIZE_OPT 
ENABLE_OCSP_OPT 
PASSWORD_OPT 
VERIFY_OPT 
WHO_OPT 
EXCLUDE_OPT 
NO_TIME_OPT 
JAVASCRIPT_OPT 
ZIPFILE_OPT 
GENKEY_OPT 
MODULES_OPT 
NORECURSE_OPT 
SIGNDIR_OPT 
OUTFILE_OPT 
COMMAND_FILE_OPT 
LEAVE_ARC_OPT 
VERBOSITY_OPT 
KEYSIZE_OPT 
TOKEN_OPT 
XPI_ARC_OPT 

Definition at line 110 of file signtool.c.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 857 of file signtool.c.

{
    PRBool readOnly;
    int       retval = 0;

    outputFD = PR_STDOUT;
    errorFD = PR_STDERR;

    progName = argv[0];

    if (argc < 2) {
       usage();
    }

    excludeDirs = PL_NewHashTable(10, PL_HashString, PL_CompareStrings,
                                          PL_CompareStrings, NULL, NULL);
    extensions = PL_NewHashTable(10, PL_HashString, PL_CompareStrings,
                                          PL_CompareStrings, NULL, NULL);

    if (parse_args(argc, argv)) {
       retval = -1;
       goto cleanup;
    }

    /* Parse the command file if one was given */
    if (cmdFile) {
       if (ProcessCommandFile()) {
           retval = -1;
           goto cleanup;
       }
    }

    /* Set up output redirection */
    if (outfile) {
       if (PR_Access(outfile, PR_ACCESS_EXISTS) == PR_SUCCESS) {
           /* delete the file if it is already present */
           PR_fprintf(errorFD,
               "warning: %s already exists and will be overwritten.\n",
                                          outfile);
           warningCount++;
           if (PR_Delete(outfile) != PR_SUCCESS) {
              PR_fprintf(errorFD, "ERROR: unable to delete %s.\n", outfile);
              errorCount++;
              exit(ERRX);
           }
       }
       outputFD = PR_Open(outfile,
           PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0777);
       if (!outputFD) {
           PR_fprintf(errorFD, "ERROR: Unable to create %s.\n",
                outfile);
           errorCount++;
           exit(ERRX);
       }
       errorFD = outputFD;
    }

    /* This seems to be a fairly common user error */

    if (verify && list_certs > 0) {
       PR_fprintf (errorFD, "%s: Can't use -l and -v at the same time\n",
                     PROGRAM_NAME);
       errorCount++;
       retval = -1;
       goto cleanup;
    }

    /* -J assumes -Z now */

    if (javascript && zipfile) {
       PR_fprintf (errorFD, "%s: Can't use -J and -Z at the same time\n",
                     PROGRAM_NAME);
       PR_fprintf (errorFD, "%s: -J option will create the jar files for you\n",
                     PROGRAM_NAME);
       errorCount++;
       retval = -1;
       goto cleanup;
    }

    /* -X needs -Z */

    if (xpi_arc && !zipfile) {
       PR_fprintf (errorFD, "%s: option XPI (-X) requires option jarfile (-Z)\n",
                     PROGRAM_NAME);
       errorCount++;
       retval = -1;
       goto cleanup;
    }

    /* Less common mixing of -L with various options */

    if (list_certs > 0 && 
        (tell_who || zipfile || javascript || 
        scriptdir || extensionsGiven || exclusionsGiven || install_script)) {
       PR_fprintf(errorFD, "%s: Can't use -l or -L with that option\n",
                            PROGRAM_NAME);
       errorCount++;
       retval = -1;
       goto cleanup;
    }


    if (!cert_dir)
       cert_dir = get_default_cert_dir();

    VerifyCertDir(cert_dir, keyName);


    if (      compression_level < MIN_COMPRESSION_LEVEL || 
        compression_level > MAX_COMPRESSION_LEVEL) {
       PR_fprintf(errorFD, "Compression level must be between %d and %d.\n",
                      MIN_COMPRESSION_LEVEL, MAX_COMPRESSION_LEVEL);
       errorCount++;
       retval = -1;
       goto cleanup;
    }

    if (jartree && !keyName) {
       PR_fprintf(errorFD, "You must specify a key with which to sign.\n");
       errorCount++;
       retval = -1;
       goto cleanup;
    }

    readOnly = (genkey == NULL); /* only key generation requires write */
    if (InitCrypto(cert_dir, readOnly)) {
       PR_fprintf(errorFD, "ERROR: Cryptographic initialization failed.\n");
       errorCount++;
       retval = -1;
       goto cleanup;
    }

    if (enableOCSP) {
       SECStatus rv = CERT_EnableOCSPChecking(CERT_GetDefaultCertDB());
       if (rv != SECSuccess) {
           PR_fprintf(errorFD, "ERROR: Attempt to enable OCSP Checking failed.\n");
           errorCount++;
           retval = -1;
       }
    }

    if (verify) {
       if (VerifyJar(verify)) {
           errorCount++;
           retval = -1;
           goto cleanup;
       }
    } else if (list_certs) {
       if (ListCerts(keyName, list_certs)) {
           errorCount++;
           retval = -1;
           goto cleanup;
       }
    } else if (list_modules) {
       JarListModules();
    } else if (genkey) {
       if (GenerateCert(genkey, keySize, token)) {
           errorCount++;
           retval = -1;
           goto cleanup;
       }
    } else if (tell_who) {
       if (JarWho(tell_who)) {
           errorCount++;
           retval = -1;
           goto cleanup;
       }
    } else if (javascript && jartree) {
       /* make sure directory exists */
       PRDir * dir;
       dir = PR_OpenDir(jartree);
       if (!dir) {
           PR_fprintf(errorFD, "ERROR: unable to open directory %s.\n",
                jartree);
           errorCount++;
           retval = -1;
           goto cleanup;
       } else {
           PR_CloseDir(dir);
       }

       /* undo junk from prior runs of signtool*/
       if (RemoveAllArc(jartree)) {
           PR_fprintf(errorFD, "Error removing archive directories under %s\n",
                jartree);
           errorCount++;
           retval = -1;
           goto cleanup;
       }

       /* traverse all the htm|html files in the directory */
       if (InlineJavaScript(jartree, !noRecurse)) {
           retval = -1;
           goto cleanup;
       }

       /* sign any resultant .arc directories created in above step */
       if (SignAllArc(jartree, keyName, javascript, metafile, install_script,
                     optimize, !noRecurse)) {
           retval = -1;
           goto cleanup;
       }

       if (!leaveArc) {
           RemoveAllArc(jartree);
       }

       if (errorCount > 0 || warningCount > 0) {
           PR_fprintf(outputFD, "%d error%s, %d warning%s.\n",
                errorCount,
               errorCount == 1 ? "" : "s", warningCount, warningCount
               == 1 ? "" : "s");
       } else {
           PR_fprintf(outputFD, "Directory %s signed successfully.\n",
                jartree);
       }
    } else if (jartree) {
       SignArchive(jartree, keyName, zipfile, javascript, metafile,
                     install_script, optimize, !noRecurse);
    } else
       usage();

cleanup:
    if (extensions) {
       PL_HashTableDestroy(extensions); 
       extensions = NULL;
    }
    if (excludeDirs) {
       PL_HashTableDestroy(excludeDirs); 
       excludeDirs = NULL;
    }
    if (outputFD != PR_STDOUT) {
       PR_Close(outputFD);
    }
    rm_dash_r(TMP_OUTPUT);
    if (retval == 0) {
       if (NSS_Shutdown() != SECSuccess) {
           exit(1);
       }
    }
    return retval;
}

Here is the call graph for this function:

static int parse_args ( int  argc,
char *  argv[] 
) [static]

Definition at line 305 of file signtool.c.

{
    char      *opt;
    char      *arg;
    int       needsInc = 0;
    int       i;
    OPT_TYPE type;

    /* Loop over all arguments */
    for (i = 1; i < argc; i++) {
       opt = argv[i];
       arg = NULL;

       if (opt[0] == '-') {
           if (opt[1] == '-') {
              /* word option */
              if (i < argc - 1) {
                  needsInc = 1;
                  arg = argv[i+1];
              } else {
                  arg = NULL;
              }

              if ( !PL_strcasecmp(opt + 2, "norecurse")) {
                  type = NORECURSE_OPT;
              } else if ( !PL_strcasecmp(opt + 2, "leavearc")) {
                  type = LEAVE_ARC_OPT;
              } else if ( !PL_strcasecmp(opt + 2, "verbosity")) {
                  type = VERBOSITY_OPT;
              } else if ( !PL_strcasecmp(opt + 2, "outfile")) {
                  type = OUTFILE_OPT;
              } else if ( !PL_strcasecmp(opt + 2, "keysize")) {
                  type = KEYSIZE_OPT;
              } else if ( !PL_strcasecmp(opt + 2, "token")) {
                  type = TOKEN_OPT;
              } else {
                  PR_fprintf(errorFD, "warning: unknown option: %s\n",
                       opt);
                  warningCount++;
                  type = UNKNOWN_OPT;
              }
           } else {
              /* char option */
              if (opt[2] != '\0') {
                  arg = opt + 2;
              } else if (i < argc - 1) {
                  needsInc = 1;
                  arg = argv[i+1];
              } else {
                  arg = NULL;
              }

              switch (opt[1]) {
              case '?':
                  type = QUESTION_OPT;
                  break;
              case 'b':
                  type = BASE_OPT;
                  break;
              case 'c':
                  type = COMPRESSION_OPT;
                  break;
              case 'd':
                  type = CERT_DIR_OPT;
                  break;
              case 'e':
                  type = EXTENSION_OPT;
                  break;
              case 'f':
                  type = COMMAND_FILE_OPT;
                  break;
              case 'i':
                  type = INSTALL_SCRIPT_OPT;
                  break;
              case 'j':
                  type = SCRIPTDIR_OPT;
                  break;
              case 'k':
                  type = CERTNAME_OPT;
                  break;
              case 'l':
                  type = LIST_OBJSIGN_CERTS_OPT;
                  break;
              case 'L':
                  type = LIST_ALL_CERTS_OPT;
                  break;
              case 'm':
                  type = METAFILE_OPT;
                  break;
              case 'o':
                  type = OPTIMIZE_OPT;
                  break;
              case 'O':
                  type = ENABLE_OCSP_OPT;
                  break;
              case 'p':
                  type = PASSWORD_OPT;
                  break;
              case 'v':
                  type = VERIFY_OPT;
                  break;
              case 'w':
                  type = WHO_OPT;
                  break;
              case 'x':
                  type = EXCLUDE_OPT;
                  break;
              case 'X':
                  type = XPI_ARC_OPT;
                  break;
              case 'z':
                  type = NO_TIME_OPT;
                  break;
              case 'J':
                  type = JAVASCRIPT_OPT;
                  break;
              case 'Z':
                  type = ZIPFILE_OPT;
                  break;
              case 'G':
                  type = GENKEY_OPT;
                  break;
              case 'M':
                  type = MODULES_OPT;
                  break;
              case 's':
                  type = KEYSIZE_OPT;
                  break;
              case 't':
                  type = TOKEN_OPT;
                  break;
              default:
                  type = UNKNOWN_OPT;
                  PR_fprintf(errorFD, "warning: unrecognized option: -%c.\n",
                       
                      opt[1]);
                  warningCount++;
                  break;
              }
           }
       } else {
           type = UNKNOWN_OPT;
           if (i == argc - 1) {
              if (jartree) {
                  PR_fprintf(errorFD,
                      "warning: directory to be signed specified more than once.\n"
                      " Only last specification will be used.\n");
                  warningCount++;
                  PR_Free(jartree); 
                  jartree = NULL;
              }
              jartree = PL_strdup(opt);
           } else {
              PR_fprintf(errorFD, "warning: unrecognized option: %s\n", opt);
              warningCount++;
           }
       }

       if (type != UNKNOWN_OPT) {
           short     ateArg = ProcessOneOpt(type, arg);
           if (ateArg == -1) {
              /* error */
              return - 1;
           } 
           if (ateArg && needsInc) {
              i++;
           }
       }
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file signtool.c.

{
    PRFileDesc * fd;
#define CMD_FILE_BUFSIZE 1024
    char      buf[CMD_FILE_BUFSIZE];
    char      *equals;
    int       linenum = 0;
    int       retval = -1;
    OPT_TYPE type;

    fd = PR_Open(cmdFile, PR_RDONLY, 0777);
    if (!fd) {
       PR_fprintf(errorFD, "ERROR: Unable to open command file %s.\n");
       errorCount++;
       return - 1;
    }

    while (pr_fgets(buf, CMD_FILE_BUFSIZE, fd), buf && *buf != '\0') {
       char   *eol;
       linenum++;

       /* Chop off final newline */
       eol = PL_strchr(buf, '\r');
       if (!eol) {
           eol = PL_strchr(buf, '\n');
       }
       if (eol) 
           *eol = '\0';

       equals = PL_strchr(buf, '=');
       if (!equals) {
           continue;
       }

       *equals = '\0';
       equals++;

       /* Now buf points to the attribute, and equals points to the value. */

       /* This is pretty straightforward, just deal with whatever attribute
               * this is */
       if (!PL_strcasecmp(buf, "basename")) {
           type = BASE_OPT;
       } else if (!PL_strcasecmp(buf, "compression")) {
           type = COMPRESSION_OPT;
       } else if (!PL_strcasecmp(buf, "certdir")) {
           type = CERT_DIR_OPT;
       } else if (!PL_strcasecmp(buf, "extension")) {
           type = EXTENSION_OPT;
       } else if (!PL_strcasecmp(buf, "generate")) {
           type = GENKEY_OPT;
       } else if (!PL_strcasecmp(buf, "installScript")) {
           type = INSTALL_SCRIPT_OPT;
       } else if (!PL_strcasecmp(buf, "javascriptdir")) {
           type = SCRIPTDIR_OPT;
       } else if (!PL_strcasecmp(buf, "htmldir")) {
           type = JAVASCRIPT_OPT;
           if (jartree) {
              PR_fprintf(errorFD,
                  "warning: directory to be signed specified more than once."
                  " Only last specification will be used.\n");
              warningCount++;
              PR_Free(jartree); 
              jartree = NULL;
           }
           jartree = PL_strdup(equals);
       } else if (!PL_strcasecmp(buf, "certname")) {
           type = CERTNAME_OPT;
       } else if (!PL_strcasecmp(buf, "signdir")) {
           type = SIGNDIR_OPT;
       } else if (!PL_strcasecmp(buf, "list")) {
           type = LIST_OBJSIGN_CERTS_OPT;
       } else if (!PL_strcasecmp(buf, "listall")) {
           type = LIST_ALL_CERTS_OPT;
       } else if (!PL_strcasecmp(buf, "metafile")) {
           type = METAFILE_OPT;
       } else if (!PL_strcasecmp(buf, "modules")) {
           type = MODULES_OPT;
       } else if (!PL_strcasecmp(buf, "optimize")) {
           type = OPTIMIZE_OPT;
       } else if (!PL_strcasecmp(buf, "ocsp")) {
           type = ENABLE_OCSP_OPT;
       } else if (!PL_strcasecmp(buf, "password")) {
           type = PASSWORD_OPT;
       } else if (!PL_strcasecmp(buf, "verify")) {
           type = VERIFY_OPT;
       } else if (!PL_strcasecmp(buf, "who")) {
           type = WHO_OPT;
       } else if (!PL_strcasecmp(buf, "exclude")) {
           type = EXCLUDE_OPT;
       } else if (!PL_strcasecmp(buf, "notime")) {
           type = NO_TIME_OPT;
       } else if (!PL_strcasecmp(buf, "jarfile")) {
           type = ZIPFILE_OPT;
       } else if (!PL_strcasecmp(buf, "outfile")) {
           type = OUTFILE_OPT;
       } else if (!PL_strcasecmp(buf, "leavearc")) {
           type = LEAVE_ARC_OPT;
       } else if (!PL_strcasecmp(buf, "verbosity")) {
           type = VERBOSITY_OPT;
       } else if (!PL_strcasecmp(buf, "keysize")) {
           type = KEYSIZE_OPT;
       } else if (!PL_strcasecmp(buf, "token")) {
           type = TOKEN_OPT;
       } else if (!PL_strcasecmp(buf, "xpi")) {
           type = XPI_ARC_OPT;
       } else {
           PR_fprintf(errorFD,
               "warning: unknown attribute \"%s\" in command file, line %d.\n",
                                                 buf, linenum);
           warningCount++;
           type = UNKNOWN_OPT;
       }

       /* Process the option, whatever it is */
       if (type != UNKNOWN_OPT) {
           if (ProcessOneOpt(type, equals) == -1) {
              goto finish;
           }
       }
    }

    retval = 0;

finish:
    PR_Close(fd);
    return retval;
}

Here is the call graph for this function:

static int ProcessOneOpt ( OPT_TYPE  type,
char *  arg 
) [static]

Definition at line 492 of file signtool.c.

{
    int       ate = 0;

    switch (type) {
    case QUESTION_OPT:
       usage();
       break;
    case BASE_OPT:
       if (base) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR], "-b");
           warningCount++;
           PR_Free(base); 
           base = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR], "-b");
           errorCount++;
           goto loser;
       }
       base = PL_strdup(arg);
       ate = 1;
       break;
    case COMPRESSION_OPT:
       if (compression_level_specified) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR], "-c");
           warningCount++;
       }
       if ( !arg ) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR], "-c");
           errorCount++;
           goto loser;
       }
       compression_level = atoi(arg);
       compression_level_specified = PR_TRUE;
       ate = 1;
       break;
    case CERT_DIR_OPT:
       if (cert_dir) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR], "-d");
           warningCount++;
           PR_Free(cert_dir); 
           cert_dir = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR], "-d");
           errorCount++;
           goto loser;
       }
       cert_dir = PL_strdup(arg);
       ate = 1;
       break;
    case EXTENSION_OPT:
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "extension (-e)");
           errorCount++;
           goto loser;
       }
       PL_HashTableAdd(extensions, arg, arg);
       extensionsGiven = PR_TRUE;
       ate = 1;
       break;
    case INSTALL_SCRIPT_OPT:
       if (install_script) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "installScript (-i)");
           warningCount++;
           PR_Free(install_script); 
           install_script = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "installScript (-i)");
           errorCount++;
           goto loser;
       }
       install_script = PL_strdup(arg);
       ate = 1;
       break;
    case SCRIPTDIR_OPT:
       if (scriptdir) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "javascriptdir (-j)");
           warningCount++;
           PR_Free(scriptdir); 
           scriptdir = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "javascriptdir (-j)");
           errorCount++;
           goto loser;
       }
       scriptdir = PL_strdup(arg);
       ate = 1;
       break;
    case CERTNAME_OPT:
       if (keyName) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "keyName (-k)");
           warningCount++;
           PR_Free(keyName); 
           keyName = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "keyName (-k)");
           errorCount++;
           goto loser;
       }
       keyName = PL_strdup(arg);
       ate = 1;
       break;
    case LIST_OBJSIGN_CERTS_OPT:
    case LIST_ALL_CERTS_OPT:
       if (list_certs != 0) {
           PR_fprintf(errorFD,
               "warning: only one of -l and -L may be specified.\n");
           warningCount++;
       }
       list_certs = (type == LIST_OBJSIGN_CERTS_OPT ? 1 : 2);
       break;
    case METAFILE_OPT:
       if (metafile) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "metafile (-m)");
           warningCount++;
           PR_Free(metafile); 
           metafile = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "metafile (-m)");
           errorCount++;
           goto loser;
       }
       metafile = PL_strdup(arg);
       ate = 1;
       break;
    case OPTIMIZE_OPT:
       optimize = 1;
       break;
    case ENABLE_OCSP_OPT:
       enableOCSP = 1;
       break;
    case PASSWORD_OPT:
       if (password) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "password (-p)");
           warningCount++;
           PR_Free(password); 
           password = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "password (-p)");
           errorCount++;
           goto loser;
       }
       password = PL_strdup(arg);
       ate = 1;
       break;
    case VERIFY_OPT:
       if (verify) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "verify (-v)");
           warningCount++;
           PR_Free(verify); 
           verify = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "verify (-v)");
           errorCount++;
           goto loser;
       }
       verify = PL_strdup(arg);
       ate = 1;
       break;
    case WHO_OPT:
       if (tell_who) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "who (-v)");
           warningCount++;
           PR_Free(tell_who); 
           tell_who = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "who (-w)");
           errorCount++;
           goto loser;
       }
       tell_who = PL_strdup(arg);
       ate = 1;
       break;
    case EXCLUDE_OPT:
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "exclude (-x)");
           errorCount++;
           goto loser;
       }
       PL_HashTableAdd(excludeDirs, arg, arg);
       exclusionsGiven = PR_TRUE;
       ate = 1;
       break;
    case NO_TIME_OPT:
       no_time = 1;
       break;
    case JAVASCRIPT_OPT:
       javascript++;
       break;
    case ZIPFILE_OPT:
       if (zipfile) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "jarfile (-Z)");
           warningCount++;
           PR_Free(zipfile); 
           zipfile = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "jarfile (-Z)");
           errorCount++;
           goto loser;
       }
       zipfile = PL_strdup(arg);
       ate = 1;
       break;
    case GENKEY_OPT:
       if (genkey) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "generate (-G)");
           warningCount++;
           PR_Free(zipfile); 
           zipfile = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                          "generate (-G)");
           errorCount++;
           goto loser;
       }
       genkey = PL_strdup(arg);
       ate = 1;
       break;
    case MODULES_OPT:
       list_modules++;
       break;
    case SIGNDIR_OPT:
       if (jartree) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "signdir");
           warningCount++;
           PR_Free(jartree); 
           jartree = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                "signdir");
           errorCount++;
           goto loser;
       }
       jartree = PL_strdup(arg);
       ate = 1;
       break;
    case OUTFILE_OPT:
       if (outfile) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                                          "outfile");
           warningCount++;
           PR_Free(outfile); 
           outfile = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                "outfile");
           errorCount++;
           goto loser;
       }
       outfile = PL_strdup(arg);
       ate = 1;
       break;
    case COMMAND_FILE_OPT:
       if (cmdFile) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR],
                "-f");
           warningCount++;
           PR_Free(cmdFile); 
           cmdFile = NULL;
       }
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                "-f");
           errorCount++;
           goto loser;
       }
       cmdFile = PL_strdup(arg);
       ate = 1;
       break;
    case NORECURSE_OPT:
       noRecurse = PR_TRUE;
       break;
    case LEAVE_ARC_OPT:
       leaveArc = PR_TRUE;
       break;
    case VERBOSITY_OPT:
       if (!arg) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR],
                                     "--verbosity");
           errorCount++;
           goto loser;
       }
       verbosity = atoi(arg);
       ate = 1;
       break;
    case KEYSIZE_OPT:
       if ( keySize != -1 ) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR], "-s");
           warningCount++;
       }
       keySize = atoi(arg);
       ate = 1;
       if ( keySize < 1 || keySize > MAX_RSA_KEY_SIZE ) {
           PR_fprintf(errorFD, "Invalid key size: %d.\n", keySize);
           errorCount++;
           goto loser;
       }
       break;
    case TOKEN_OPT:
       if ( token ) {
           PR_fprintf(errorFD, errStrings[DUPLICATE_OPTION_ERR], "-t");
           PR_Free(token); 
           token = NULL;
       }
       if ( !arg ) {
           PR_fprintf(errorFD, errStrings[OPTION_NEEDS_ARG_ERR], "-t");
           errorCount++;
           goto loser;
       }
       token = PL_strdup(arg);
       ate = 1;
       break;
    case XPI_ARC_OPT:
       xpi_arc = 1;
       break;
    default:
       PR_fprintf(errorFD, "warning: unknown option\n");
       warningCount++;
       break;
    }

    return ate;
loser:
    return - 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 69 of file signtool.c.

char* cert_dir = NULL [static]

Definition at line 92 of file signtool.c.

char* cmdFile = NULL [static]

Definition at line 104 of file signtool.c.

Definition at line 83 of file signtool.c.

Definition at line 84 of file signtool.c.

int enableOCSP = 0 [static]

Definition at line 101 of file signtool.c.

Definition at line 81 of file signtool.c.

Definition at line 79 of file signtool.c.

char* errStrings[] [static]
Initial value:
 {
    "warning: %s option specified more than once.\n"
    "Only last specification will be used.\n",
    "ERROR: option \"%s\" requires an argument.\n"
}

Definition at line 156 of file signtool.c.

Definition at line 62 of file signtool.c.

Definition at line 63 of file signtool.c.

Definition at line 72 of file signtool.c.

Definition at line 73 of file signtool.c.

char* genkey = NULL [static]

Definition at line 89 of file signtool.c.

char* install_script = NULL [static]

Definition at line 97 of file signtool.c.

char* jartree = NULL [static]

Definition at line 94 of file signtool.c.

int javascript = 0 [static]

Definition at line 93 of file signtool.c.

char* keyName = NULL [static]

Definition at line 95 of file signtool.c.

int keySize = -1 [static]

Definition at line 107 of file signtool.c.

PRBool leaveArc = PR_FALSE [static]

Definition at line 106 of file signtool.c.

int list_certs = 0 [static]

Definition at line 98 of file signtool.c.

int list_modules = 0 [static]

Definition at line 99 of file signtool.c.

char* metafile = NULL [static]

Definition at line 96 of file signtool.c.

int no_time = 0

Definition at line 66 of file signtool.c.

Definition at line 105 of file signtool.c.

int optimize = 0 [static]

Definition at line 100 of file signtool.c.

char* outfile = NULL [static]

Definition at line 103 of file signtool.c.

Definition at line 79 of file signtool.c.

char* password = NULL

Definition at line 59 of file signtool.c.

char* progName

Definition at line 56 of file signtool.c.

char* scriptdir = NULL

Definition at line 75 of file signtool.c.

char* tell_who = NULL [static]

Definition at line 102 of file signtool.c.

char* token = NULL [static]

Definition at line 108 of file signtool.c.

Definition at line 77 of file signtool.c.

char* verify = NULL [static]

Definition at line 90 of file signtool.c.

Definition at line 81 of file signtool.c.

int xpi_arc = 0

Definition at line 86 of file signtool.c.

char* zipfile = NULL [static]

Definition at line 91 of file signtool.c.