PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/security/nss/cmd/modutil/instsec.c

http://github.com/zpao/v8monkey
C | 182 lines | 98 code | 21 blank | 63 comment | 17 complexity | 16e26ef5935d0b475d8e5aa457ab464d MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is the Netscape security libraries.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * Netscape Communications Corporation.
 18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
 19 * the Initial Developer. All Rights Reserved.
 20 *
 21 * Contributor(s):
 22 *
 23 * Alternatively, the contents of this file may be used under the terms of
 24 * either the GNU General Public License Version 2 or later (the "GPL"), or
 25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 26 * in which case the provisions of the GPL or the LGPL are applicable instead
 27 * of those above. If you wish to allow use of your version of this file only
 28 * under the terms of either the GPL or the LGPL, and not to allow others to
 29 * use your version of this file under the terms of the MPL, indicate your
 30 * decision by deleting the provisions above and replace them with the notice
 31 * and other provisions required by the GPL or the LGPL. If you do not delete
 32 * the provisions above, a recipient may use your version of this file under
 33 * the terms of any one of the MPL, the GPL or the LGPL.
 34 *
 35 * ***** END LICENSE BLOCK ***** */
 36
 37#include <plarena.h>
 38#include <prerror.h>
 39#include <prio.h>
 40#include <prprf.h>
 41#include <seccomon.h>
 42#include <secmod.h>
 43#include <jar.h>
 44#include <secutil.h>
 45
 46/* These are installation functions that make calls to the security library.
 47 * We don't want to include security include files in the C++ code too much.
 48 */
 49
 50static char* PR_fgets(char *buf, int size, PRFileDesc *file);
 51
 52/***************************************************************************
 53 *
 54 * P k 1 1 I n s t a l l _ A d d N e w M o d u l e
 55 */
 56int
 57Pk11Install_AddNewModule(char* moduleName, char* dllPath,
 58                              unsigned long defaultMechanismFlags,
 59                              unsigned long cipherEnableFlags)
 60{
 61	return (SECMOD_AddNewModule(moduleName, dllPath,
 62		SECMOD_PubMechFlagstoInternal(defaultMechanismFlags),
 63		SECMOD_PubCipherFlagstoInternal(cipherEnableFlags))
 64													== SECSuccess) ? 0 : -1;
 65}
 66
 67/*************************************************************************
 68 *
 69 * P k 1 1 I n s t a l l _ U s e r V e r i f y J a r
 70 *
 71 * Gives the user feedback on the signatures of a JAR files, asks them
 72 * whether they actually want to continue.
 73 * Assumes the jar structure has already been created and is valid.
 74 * Returns 0 if the user wants to continue the installation, nonzero
 75 * if the user wishes to abort.
 76 */
 77short
 78Pk11Install_UserVerifyJar(JAR *jar, PRFileDesc *out, PRBool query)
 79{
 80	JAR_Context *ctx;
 81	JAR_Cert *fing;
 82	JAR_Item *item;
 83	char stdinbuf[80];
 84	int count=0;
 85
 86	CERTCertificate *cert, *prev=NULL;
 87
 88	PR_fprintf(out, "\nThis installation JAR file was signed by:\n");
 89
 90	ctx = JAR_find(jar, NULL, jarTypeSign);
 91
 92	while(JAR_find_next(ctx, &item) >= 0 ) {
 93		fing = (JAR_Cert*) item->data;
 94		cert = fing->cert;
 95		if(cert==prev) {
 96			continue;
 97		}
 98
 99		count++;
100		PR_fprintf(out, "----------------------------------------------\n");
101		if(cert) {
102			if(cert->nickname) {
103				PR_fprintf(out, "**NICKNAME**\n%s\n", cert->nickname);
104			}
105			if(cert->subjectName) {
106				PR_fprintf(out, "**SUBJECT NAME**\n%s\n", cert->subjectName); }
107			if(cert->issuerName) {
108				PR_fprintf(out, "**ISSUER NAME**\n%s\n", cert->issuerName);
109			}
110		} else {
111			PR_fprintf(out, "No matching certificate could be found.\n");
112		}
113		PR_fprintf(out, "----------------------------------------------\n\n");
114
115		prev=cert;
116	}
117
118	JAR_find_end(ctx);
119
120	if(count==0) {
121		PR_fprintf(out, "No signatures found: JAR FILE IS UNSIGNED.\n");
122	}
123
124	if(query) {
125		PR_fprintf(out,
126"Do you wish to continue this installation? (y/n) ");
127
128		if(PR_fgets(stdinbuf, 80, PR_STDIN) != NULL) {
129			char *response;
130
131			if( (response=strtok(stdinbuf, " \t\n\r")) ) {
132				if( !PL_strcasecmp(response, "y") ||
133					!PL_strcasecmp(response, "yes") ) {
134					return 0;
135				}
136			}
137		}
138	}
139
140	return 1;
141}
142
143/**************************************************************************
144 *
145 * P R _ f g e t s
146 *
147 * fgets implemented with NSPR.
148 */
149static char*
150PR_fgets(char *buf, int size, PRFileDesc *file)
151{
152    int i;
153    int status;
154    char c;
155
156    i=0;
157    while(i < size-1) {
158        status = PR_Read(file, (void*) &c, 1);
159        if(status==-1) {
160            return NULL;
161        } else if(status==0) {
162            break;
163        }
164        buf[i++] = c;
165        if(c=='\n') {
166            break;
167        }
168    }
169    buf[i]='\0';
170
171    return buf;
172}
173
174/**************************************************************************
175 *
176 * m y S E C U _ E r r o r S t r i n g
177 *
178 */
179const char* mySECU_ErrorString(PRErrorCode errnum)
180{
181	return SECU_Strerror(errnum);
182}