summaryrefslogtreecommitdiff
path: root/lib/jar
diff options
context:
space:
mode:
authorFranziskus Kiefer <franziskuskiefer@gmail.com>2016-03-07 16:42:59 +0100
committerFranziskus Kiefer <franziskuskiefer@gmail.com>2016-03-07 16:42:59 +0100
commit582f5030a3e1dc5a259e58655463a13cb294c865 (patch)
tree30ef41284c1c59ecf4329feec9761104b5abf37c /lib/jar
parent186e404c519e4d788ab5ef2d31ca4951498ea3f6 (diff)
downloadnss-hg-582f5030a3e1dc5a259e58655463a13cb294c865.tar.gz
Bug 1254153 - clang-format on lib/jar, r=kaie
Diffstat (limited to 'lib/jar')
-rw-r--r--lib/jar/jar-ds.c14
-rw-r--r--lib/jar/jar-ds.h67
-rw-r--r--lib/jar/jar.c783
-rw-r--r--lib/jar/jar.h149
-rw-r--r--lib/jar/jarfile.c962
-rw-r--r--lib/jar/jarfile.h102
-rw-r--r--lib/jar/jarint.c20
-rw-r--r--lib/jar/jarint.h35
-rw-r--r--lib/jar/jarnav.c35
-rw-r--r--lib/jar/jarsign.c172
-rw-r--r--lib/jar/jarver.c996
-rw-r--r--lib/jar/jzconf.h174
-rw-r--r--lib/jar/jzlib.h284
13 files changed, 1897 insertions, 1896 deletions
diff --git a/lib/jar/jar-ds.c b/lib/jar/jar-ds.c
index 0d787baa6..8962305ca 100644
--- a/lib/jar/jar-ds.c
+++ b/lib/jar/jar-ds.c
@@ -8,29 +8,29 @@
ZZList *
ZZ_NewList(void)
{
- ZZList *list = (ZZList *) PORT_ZAlloc (sizeof (ZZList));
+ ZZList *list = (ZZList *)PORT_ZAlloc(sizeof(ZZList));
if (list)
- ZZ_InitList (list);
+ ZZ_InitList(list);
return list;
}
ZZLink *
ZZ_NewLink(JAR_Item *thing)
{
- ZZLink *link = (ZZLink *) PORT_ZAlloc (sizeof (ZZLink));
+ ZZLink *link = (ZZLink *)PORT_ZAlloc(sizeof(ZZLink));
if (link)
- link->thing = thing;
+ link->thing = thing;
return link;
}
-void
+void
ZZ_DestroyLink(ZZLink *link)
{
PORT_Free(link);
}
-void
-ZZ_DestroyList (ZZList *list)
+void
+ZZ_DestroyList(ZZList *list)
{
PORT_Free(list);
}
diff --git a/lib/jar/jar-ds.h b/lib/jar/jar-ds.h
index dd212e47b..9818c66c9 100644
--- a/lib/jar/jar-ds.h
+++ b/lib/jar/jar-ds.h
@@ -23,12 +23,12 @@ struct ZZListStr {
ZZLink link;
};
-#define ZZ_InitList(lst) \
-{ \
- (lst)->link.next = &(lst)->link; \
- (lst)->link.prev = &(lst)->link; \
- (lst)->link.thing = 0; \
-}
+#define ZZ_InitList(lst) \
+ { \
+ (lst)->link.next = &(lst)->link; \
+ (lst)->link.prev = &(lst)->link; \
+ (lst)->link.thing = 0; \
+ }
#define ZZ_ListEmpty(lst) ((lst)->link.next == &(lst)->link)
@@ -36,43 +36,42 @@ struct ZZListStr {
#define ZZ_ListTail(lst) ((lst)->link.prev)
-#define ZZ_ListIterDone(lst,lnk) ((lnk) == &(lst)->link)
-
-#define ZZ_AppendLink(lst,lnk) \
-{ \
- (lnk)->next = &(lst)->link; \
- (lnk)->prev = (lst)->link.prev; \
- (lst)->link.prev->next = (lnk); \
- (lst)->link.prev = (lnk); \
-}
-
-#define ZZ_InsertLink(lst,lnk) \
-{ \
- (lnk)->next = (lst)->link.next; \
- (lnk)->prev = &(lst)->link; \
- (lst)->link.next->prev = (lnk); \
- (lst)->link.next = (lnk); \
-}
-
-#define ZZ_RemoveLink(lnk) \
-{ \
- (lnk)->next->prev = (lnk)->prev; \
- (lnk)->prev->next = (lnk)->next; \
- (lnk)->next = 0; \
- (lnk)->prev = 0; \
-}
+#define ZZ_ListIterDone(lst, lnk) ((lnk) == &(lst)->link)
+
+#define ZZ_AppendLink(lst, lnk) \
+ { \
+ (lnk)->next = &(lst)->link; \
+ (lnk)->prev = (lst)->link.prev; \
+ (lst)->link.prev->next = (lnk); \
+ (lst)->link.prev = (lnk); \
+ }
+
+#define ZZ_InsertLink(lst, lnk) \
+ { \
+ (lnk)->next = (lst)->link.next; \
+ (lnk)->prev = &(lst)->link; \
+ (lst)->link.next->prev = (lnk); \
+ (lst)->link.next = (lnk); \
+ }
+
+#define ZZ_RemoveLink(lnk) \
+ { \
+ (lnk)->next->prev = (lnk)->prev; \
+ (lnk)->prev->next = (lnk)->next; \
+ (lnk)->next = 0; \
+ (lnk)->prev = 0; \
+ }
extern ZZLink *
ZZ_NewLink(JAR_Item *thing);
-extern void
+extern void
ZZ_DestroyLink(ZZLink *link);
extern ZZList *
ZZ_NewList(void);
-extern void
+extern void
ZZ_DestroyList(ZZList *list);
-
#endif /* __JAR_DS_h_ */
diff --git a/lib/jar/jar.c b/lib/jar/jar.c
index d7aadbbeb..520a179e2 100644
--- a/lib/jar/jar.c
+++ b/lib/jar/jar.c
@@ -14,10 +14,10 @@
#include "jarint.h"
#include "portreg.h"
-static void
-jar_destroy_list (ZZList *list);
+static void
+jar_destroy_list(ZZList *list);
-static int
+static int
jar_find_first_cert(JAR_Signer *signer, int type, JAR_Item **it);
/*
@@ -32,33 +32,33 @@ JAR_new(void)
{
JAR *jar;
- if ((jar = (JAR*)PORT_ZAlloc (sizeof (JAR))) == NULL)
- goto loser;
+ if ((jar = (JAR *)PORT_ZAlloc(sizeof(JAR))) == NULL)
+ goto loser;
if ((jar->manifest = ZZ_NewList()) == NULL)
- goto loser;
+ goto loser;
if ((jar->hashes = ZZ_NewList()) == NULL)
- goto loser;
+ goto loser;
if ((jar->phy = ZZ_NewList()) == NULL)
- goto loser;
+ goto loser;
if ((jar->metainfo = ZZ_NewList()) == NULL)
- goto loser;
+ goto loser;
if ((jar->signers = ZZ_NewList()) == NULL)
- goto loser;
+ goto loser;
return jar;
loser:
if (jar) {
- if (jar->manifest)
- ZZ_DestroyList (jar->manifest);
- if (jar->hashes)
- ZZ_DestroyList (jar->hashes);
- if (jar->phy)
- ZZ_DestroyList (jar->phy);
- if (jar->metainfo)
- ZZ_DestroyList (jar->metainfo);
- if (jar->signers)
- ZZ_DestroyList (jar->signers);
- PORT_Free (jar);
+ if (jar->manifest)
+ ZZ_DestroyList(jar->manifest);
+ if (jar->hashes)
+ ZZ_DestroyList(jar->hashes);
+ if (jar->phy)
+ ZZ_DestroyList(jar->phy);
+ if (jar->metainfo)
+ ZZ_DestroyList(jar->metainfo);
+ if (jar->signers)
+ ZZ_DestroyList(jar->signers);
+ PORT_Free(jar);
}
return NULL;
}
@@ -66,36 +66,36 @@ loser:
/*
* J A R _ d e s t r o y
*/
-void PR_CALLBACK
+void PR_CALLBACK
JAR_destroy(JAR *jar)
{
- PORT_Assert( jar != NULL );
+ PORT_Assert(jar != NULL);
if (jar == NULL)
- return;
+ return;
- if (jar->fp)
- JAR_FCLOSE ((PRFileDesc*)jar->fp);
- if (jar->url)
- PORT_Free (jar->url);
- if (jar->filename)
- PORT_Free (jar->filename);
+ if (jar->fp)
+ JAR_FCLOSE((PRFileDesc *)jar->fp);
+ if (jar->url)
+ PORT_Free(jar->url);
+ if (jar->filename)
+ PORT_Free(jar->filename);
/* Free the linked list elements */
- jar_destroy_list (jar->manifest);
- ZZ_DestroyList (jar->manifest);
- jar_destroy_list (jar->hashes);
- ZZ_DestroyList (jar->hashes);
- jar_destroy_list (jar->phy);
- ZZ_DestroyList (jar->phy);
- jar_destroy_list (jar->metainfo);
- ZZ_DestroyList (jar->metainfo);
- jar_destroy_list (jar->signers);
- ZZ_DestroyList (jar->signers);
- PORT_Free (jar);
+ jar_destroy_list(jar->manifest);
+ ZZ_DestroyList(jar->manifest);
+ jar_destroy_list(jar->hashes);
+ ZZ_DestroyList(jar->hashes);
+ jar_destroy_list(jar->phy);
+ ZZ_DestroyList(jar->phy);
+ jar_destroy_list(jar->metainfo);
+ ZZ_DestroyList(jar->metainfo);
+ jar_destroy_list(jar->signers);
+ ZZ_DestroyList(jar->signers);
+ PORT_Free(jar);
}
-static void
+static void
jar_destroy_list(ZZList *list)
{
ZZLink *link, *oldlink;
@@ -106,70 +106,70 @@ jar_destroy_list(ZZList *list)
JAR_Metainfo *met;
JAR_Signer *signer;
- if (list && !ZZ_ListEmpty (list)) {
- link = ZZ_ListHead (list);
- while (!ZZ_ListIterDone (list, link)) {
- it = link->thing;
- if (!it)
- goto next;
- if (it->pathname)
- PORT_Free (it->pathname);
-
- switch (it->type) {
- case jarTypeMeta:
- met = (JAR_Metainfo *) it->data;
- if (met) {
- if (met->header)
- PORT_Free (met->header);
- if (met->info)
- PORT_Free (met->info);
- PORT_Free (met);
- }
- break;
-
- case jarTypePhy:
- phy = (JAR_Physical *) it->data;
- if (phy)
- PORT_Free (phy);
- break;
-
- case jarTypeSign:
- fing = (JAR_Cert *) it->data;
- if (fing) {
- if (fing->cert)
- CERT_DestroyCertificate (fing->cert);
- if (fing->key)
- PORT_Free (fing->key);
- PORT_Free (fing);
- }
- break;
-
- case jarTypeSect:
- case jarTypeMF:
- case jarTypeSF:
- dig = (JAR_Digest *) it->data;
- if (dig) {
- PORT_Free (dig);
- }
- break;
-
- case jarTypeOwner:
- signer = (JAR_Signer *) it->data;
- if (signer)
- JAR_destroy_signer (signer);
- break;
-
- default:
- /* PORT_Assert( 1 != 2 ); */
- break;
- }
- PORT_Free (it);
-
-next:
- oldlink = link;
- link = link->next;
- ZZ_DestroyLink (oldlink);
- }
+ if (list && !ZZ_ListEmpty(list)) {
+ link = ZZ_ListHead(list);
+ while (!ZZ_ListIterDone(list, link)) {
+ it = link->thing;
+ if (!it)
+ goto next;
+ if (it->pathname)
+ PORT_Free(it->pathname);
+
+ switch (it->type) {
+ case jarTypeMeta:
+ met = (JAR_Metainfo *)it->data;
+ if (met) {
+ if (met->header)
+ PORT_Free(met->header);
+ if (met->info)
+ PORT_Free(met->info);
+ PORT_Free(met);
+ }
+ break;
+
+ case jarTypePhy:
+ phy = (JAR_Physical *)it->data;
+ if (phy)
+ PORT_Free(phy);
+ break;
+
+ case jarTypeSign:
+ fing = (JAR_Cert *)it->data;
+ if (fing) {
+ if (fing->cert)
+ CERT_DestroyCertificate(fing->cert);
+ if (fing->key)
+ PORT_Free(fing->key);
+ PORT_Free(fing);
+ }
+ break;
+
+ case jarTypeSect:
+ case jarTypeMF:
+ case jarTypeSF:
+ dig = (JAR_Digest *)it->data;
+ if (dig) {
+ PORT_Free(dig);
+ }
+ break;
+
+ case jarTypeOwner:
+ signer = (JAR_Signer *)it->data;
+ if (signer)
+ JAR_destroy_signer(signer);
+ break;
+
+ default:
+ /* PORT_Assert( 1 != 2 ); */
+ break;
+ }
+ PORT_Free(it);
+
+ next:
+ oldlink = link;
+ link = link->next;
+ ZZ_DestroyLink(oldlink);
+ }
}
}
@@ -181,42 +181,42 @@ next:
*
*/
-int
-JAR_get_metainfo(JAR *jar, char *name, char *header, void **info,
+int
+JAR_get_metainfo(JAR *jar, char *name, char *header, void **info,
unsigned long *length)
{
JAR_Item *it;
ZZLink *link;
ZZList *list;
- PORT_Assert( jar != NULL && header != NULL );
+ PORT_Assert(jar != NULL && header != NULL);
if (jar == NULL || header == NULL)
- return JAR_ERR_PNF;
+ return JAR_ERR_PNF;
list = jar->metainfo;
- if (ZZ_ListEmpty (list))
- return JAR_ERR_PNF;
+ if (ZZ_ListEmpty(list))
+ return JAR_ERR_PNF;
- for (link = ZZ_ListHead (list);
- !ZZ_ListIterDone (list, link);
+ for (link = ZZ_ListHead(list);
+ !ZZ_ListIterDone(list, link);
link = link->next) {
- it = link->thing;
- if (it->type == jarTypeMeta) {
- JAR_Metainfo *met;
-
- if ((name && !it->pathname) || (!name && it->pathname))
- continue;
- if (name && it->pathname && strcmp (it->pathname, name))
- continue;
- met = (JAR_Metainfo *) it->data;
- if (!PORT_Strcasecmp (met->header, header)) {
- *info = PORT_Strdup (met->info);
- *length = PORT_Strlen (met->info);
- return 0;
- }
- }
+ it = link->thing;
+ if (it->type == jarTypeMeta) {
+ JAR_Metainfo *met;
+
+ if ((name && !it->pathname) || (!name && it->pathname))
+ continue;
+ if (name && it->pathname && strcmp(it->pathname, name))
+ continue;
+ met = (JAR_Metainfo *)it->data;
+ if (!PORT_Strcasecmp(met->header, header)) {
+ *info = PORT_Strdup(met->info);
+ *length = PORT_Strlen(met->info);
+ return 0;
+ }
+ }
}
return JAR_ERR_PNF;
}
@@ -232,61 +232,61 @@ JAR_get_metainfo(JAR *jar, char *name, char *header, void **info,
*
*/
JAR_Context *
-JAR_find (JAR *jar, char *pattern, jarType type)
+JAR_find(JAR *jar, char *pattern, jarType type)
{
JAR_Context *ctx;
- PORT_Assert( jar != NULL );
+ PORT_Assert(jar != NULL);
if (!jar)
- return NULL;
+ return NULL;
- ctx = (JAR_Context *) PORT_ZAlloc (sizeof (JAR_Context));
+ ctx = (JAR_Context *)PORT_ZAlloc(sizeof(JAR_Context));
if (ctx == NULL)
- return NULL;
+ return NULL;
ctx->jar = jar;
if (pattern) {
- if ((ctx->pattern = PORT_Strdup (pattern)) == NULL) {
- PORT_Free (ctx);
- return NULL;
- }
+ if ((ctx->pattern = PORT_Strdup(pattern)) == NULL) {
+ PORT_Free(ctx);
+ return NULL;
+ }
}
ctx->finding = type;
switch (type) {
- case jarTypeMF:
- ctx->next = ZZ_ListHead (jar->hashes);
- break;
-
- case jarTypeSF:
- case jarTypeSign:
- ctx->next = NULL;
- ctx->nextsign = ZZ_ListHead (jar->signers);
- break;
-
- case jarTypeSect:
- ctx->next = ZZ_ListHead (jar->manifest);
- break;
-
- case jarTypePhy:
- ctx->next = ZZ_ListHead (jar->phy);
- break;
-
- case jarTypeOwner:
- if (jar->signers)
- ctx->next = ZZ_ListHead (jar->signers);
- else
- ctx->next = NULL;
- break;
-
- case jarTypeMeta:
- ctx->next = ZZ_ListHead (jar->metainfo);
- break;
-
- default:
- PORT_Assert( 1 != 2);
- break;
+ case jarTypeMF:
+ ctx->next = ZZ_ListHead(jar->hashes);
+ break;
+
+ case jarTypeSF:
+ case jarTypeSign:
+ ctx->next = NULL;
+ ctx->nextsign = ZZ_ListHead(jar->signers);
+ break;
+
+ case jarTypeSect:
+ ctx->next = ZZ_ListHead(jar->manifest);
+ break;
+
+ case jarTypePhy:
+ ctx->next = ZZ_ListHead(jar->phy);
+ break;
+
+ case jarTypeOwner:
+ if (jar->signers)
+ ctx->next = ZZ_ListHead(jar->signers);
+ else
+ ctx->next = NULL;
+ break;
+
+ case jarTypeMeta:
+ ctx->next = ZZ_ListHead(jar->metainfo);
+ break;
+
+ default:
+ PORT_Assert(1 != 2);
+ break;
}
return ctx;
}
@@ -297,14 +297,14 @@ JAR_find (JAR *jar, char *pattern, jarType type)
* Destroy the find iterator context.
*
*/
-void
-JAR_find_end (JAR_Context *ctx)
+void
+JAR_find_end(JAR_Context *ctx)
{
- PORT_Assert( ctx != NULL );
+ PORT_Assert(ctx != NULL);
if (ctx) {
- if (ctx->pattern)
- PORT_Free (ctx->pattern);
- PORT_Free (ctx);
+ if (ctx->pattern)
+ PORT_Free(ctx->pattern);
+ PORT_Free(ctx);
}
}
@@ -316,15 +316,16 @@ JAR_find_end (JAR_Context *ctx)
*
*/
-int JAR_find_next (JAR_Context *ctx, JAR_Item **it)
+int
+JAR_find_next(JAR_Context *ctx, JAR_Item **it)
{
JAR *jar;
ZZList *list = NULL;
int finding;
JAR_Signer *signer = NULL;
- PORT_Assert( ctx != NULL );
- PORT_Assert( ctx->jar != NULL );
+ PORT_Assert(ctx != NULL);
+ PORT_Assert(ctx->jar != NULL);
jar = ctx->jar;
@@ -332,184 +333,184 @@ int JAR_find_next (JAR_Context *ctx, JAR_Item **it)
the actual attached certificate later */
finding = (ctx->finding == jarTypeSign) ? jarTypeSF : ctx->finding;
if (ctx->nextsign) {
- if (ZZ_ListIterDone (jar->signers, ctx->nextsign)) {
- *it = NULL;
- return -1;
- }
- PORT_Assert (ctx->nextsign->thing != NULL);
- signer = (JAR_Signer*)ctx->nextsign->thing->data;
+ if (ZZ_ListIterDone(jar->signers, ctx->nextsign)) {
+ *it = NULL;
+ return -1;
+ }
+ PORT_Assert(ctx->nextsign->thing != NULL);
+ signer = (JAR_Signer *)ctx->nextsign->thing->data;
}
/* Find out which linked list to traverse. Then if
necessary, advance to the next linked list. */
while (1) {
- switch (finding) {
- case jarTypeSign: /* not any more */
- PORT_Assert( finding != jarTypeSign );
- list = signer->certs;
- break;
-
- case jarTypeSect:
- list = jar->manifest;
- break;
-
- case jarTypePhy:
- list = jar->phy;
- break;
-
- case jarTypeSF: /* signer, not jar */
- PORT_Assert( signer != NULL );
- list = signer ? signer->sf : NULL;
- break;
-
- case jarTypeMF:
- list = jar->hashes;
- break;
-
- case jarTypeOwner:
- list = jar->signers;
- break;
-
- case jarTypeMeta:
- list = jar->metainfo;
- break;
-
- default:
- PORT_Assert( 1 != 2 );
- list = NULL;
- break;
- }
- if (list == NULL) {
- *it = NULL;
- return -1;
- }
- /* When looping over lists of lists, advance to the next signer.
+ switch (finding) {
+ case jarTypeSign: /* not any more */
+ PORT_Assert(finding != jarTypeSign);
+ list = signer->certs;
+ break;
+
+ case jarTypeSect:
+ list = jar->manifest;
+ break;
+
+ case jarTypePhy:
+ list = jar->phy;
+ break;
+
+ case jarTypeSF: /* signer, not jar */
+ PORT_Assert(signer != NULL);
+ list = signer ? signer->sf : NULL;
+ break;
+
+ case jarTypeMF:
+ list = jar->hashes;
+ break;
+
+ case jarTypeOwner:
+ list = jar->signers;
+ break;
+
+ case jarTypeMeta:
+ list = jar->metainfo;
+ break;
+
+ default:
+ PORT_Assert(1 != 2);
+ list = NULL;
+ break;
+ }
+ if (list == NULL) {
+ *it = NULL;
+ return -1;
+ }
+ /* When looping over lists of lists, advance to the next signer.
This is done when multiple signers are possible. */
- if (ZZ_ListIterDone (list, ctx->next)) {
- if (ctx->nextsign && jar->signers) {
- ctx->nextsign = ctx->nextsign->next;
- if (!ZZ_ListIterDone (jar->signers, ctx->nextsign)) {
- PORT_Assert (ctx->nextsign->thing != NULL);
- signer = (JAR_Signer*)ctx->nextsign->thing->data;
- PORT_Assert( signer != NULL );
- ctx->next = NULL;
- continue;
- }
- }
- *it = NULL;
- return -1;
- }
-
- /* if the signer changed, still need to fill in the "next" link */
- if (ctx->nextsign && ctx->next == NULL) {
- switch (finding) {
- case jarTypeSF:
- ctx->next = ZZ_ListHead (signer->sf);
- break;
-
- case jarTypeSign:
- ctx->next = ZZ_ListHead (signer->certs);
- break;
- }
- }
- PORT_Assert( ctx->next != NULL );
- if (ctx->next == NULL) {
- *it = NULL;
- return -1;
- }
- while (!ZZ_ListIterDone (list, ctx->next)) {
- *it = ctx->next->thing;
- ctx->next = ctx->next->next;
- if (!*it || (*it)->type != finding)
- continue;
- if (ctx->pattern && *ctx->pattern) {
- if (PORT_RegExpSearch ((*it)->pathname, ctx->pattern))
- continue;
- }
- /* We have a valid match. If this is a jarTypeSign
+ if (ZZ_ListIterDone(list, ctx->next)) {
+ if (ctx->nextsign && jar->signers) {
+ ctx->nextsign = ctx->nextsign->next;
+ if (!ZZ_ListIterDone(jar->signers, ctx->nextsign)) {
+ PORT_Assert(ctx->nextsign->thing != NULL);
+ signer = (JAR_Signer *)ctx->nextsign->thing->data;
+ PORT_Assert(signer != NULL);
+ ctx->next = NULL;
+ continue;
+ }
+ }
+ *it = NULL;
+ return -1;
+ }
+
+ /* if the signer changed, still need to fill in the "next" link */
+ if (ctx->nextsign && ctx->next == NULL) {
+ switch (finding) {
+ case jarTypeSF:
+ ctx->next = ZZ_ListHead(signer->sf);
+ break;
+
+ case jarTypeSign:
+ ctx->next = ZZ_ListHead(signer->certs);
+ break;
+ }
+ }
+ PORT_Assert(ctx->next != NULL);
+ if (ctx->next == NULL) {
+ *it = NULL;
+ return -1;
+ }
+ while (!ZZ_ListIterDone(list, ctx->next)) {
+ *it = ctx->next->thing;
+ ctx->next = ctx->next->next;
+ if (!*it || (*it)->type != finding)
+ continue;
+ if (ctx->pattern && *ctx->pattern) {
+ if (PORT_RegExpSearch((*it)->pathname, ctx->pattern))
+ continue;
+ }
+ /* We have a valid match. If this is a jarTypeSign
return the certificate instead.. */
- if (ctx->finding == jarTypeSign) {
- JAR_Item *itt;
-
- /* just the first one for now */
- if (jar_find_first_cert (signer, jarTypeSign, &itt) >= 0) {
- *it = itt;
- return 0;
- }
- continue;
- }
- return 0;
- }
+ if (ctx->finding == jarTypeSign) {
+ JAR_Item *itt;
+
+ /* just the first one for now */
+ if (jar_find_first_cert(signer, jarTypeSign, &itt) >= 0) {
+ *it = itt;
+ return 0;
+ }
+ continue;
+ }
+ return 0;
+ }
} /* end while */
}
-static int
-jar_find_first_cert (JAR_Signer *signer, int type, JAR_Item **it)
+static int
+jar_find_first_cert(JAR_Signer *signer, int type, JAR_Item **it)
{
ZZLink *link;
ZZList *list = signer->certs;
int status = JAR_ERR_PNF;
*it = NULL;
- if (ZZ_ListEmpty (list)) {
- /* empty list */
- return JAR_ERR_PNF;
+ if (ZZ_ListEmpty(list)) {
+ /* empty list */
+ return JAR_ERR_PNF;
}
- for (link = ZZ_ListHead (list);
- !ZZ_ListIterDone (list, link);
- link = link->next) {
- if (link->thing->type == type) {
- *it = link->thing;
- status = 0;
- break;
- }
+ for (link = ZZ_ListHead(list);
+ !ZZ_ListIterDone(list, link);
+ link = link->next) {
+ if (link->thing->type == type) {
+ *it = link->thing;
+ status = 0;
+ break;
+ }
}
return status;
}
JAR_Signer *
-JAR_new_signer (void)
+JAR_new_signer(void)
{
- JAR_Signer *signer = (JAR_Signer *) PORT_ZAlloc (sizeof (JAR_Signer));
+ JAR_Signer *signer = (JAR_Signer *)PORT_ZAlloc(sizeof(JAR_Signer));
if (signer == NULL)
- goto loser;
+ goto loser;
/* certs */
signer->certs = ZZ_NewList();
if (signer->certs == NULL)
- goto loser;
+ goto loser;
/* sf */
signer->sf = ZZ_NewList();
if (signer->sf == NULL)
- goto loser;
+ goto loser;
return signer;
loser:
if (signer) {
- if (signer->certs)
- ZZ_DestroyList (signer->certs);
- if (signer->sf)
- ZZ_DestroyList (signer->sf);
- PORT_Free (signer);
+ if (signer->certs)
+ ZZ_DestroyList(signer->certs);
+ if (signer->sf)
+ ZZ_DestroyList(signer->sf);
+ PORT_Free(signer);
}
return NULL;
}
-void
+void
JAR_destroy_signer(JAR_Signer *signer)
{
if (signer) {
- if (signer->owner)
- PORT_Free (signer->owner);
- if (signer->digest)
- PORT_Free (signer->digest);
- jar_destroy_list (signer->sf);
- ZZ_DestroyList (signer->sf);
- jar_destroy_list (signer->certs);
- ZZ_DestroyList (signer->certs);
- PORT_Free (signer);
+ if (signer->owner)
+ PORT_Free(signer->owner);
+ if (signer->digest)
+ PORT_Free(signer->digest);
+ jar_destroy_list(signer->sf);
+ ZZ_DestroyList(signer->sf);
+ jar_destroy_list(signer->certs);
+ ZZ_DestroyList(signer->certs);
+ PORT_Free(signer);
}
}
@@ -517,21 +518,21 @@ JAR_Signer *
jar_get_signer(JAR *jar, char *basename)
{
JAR_Item *it;
- JAR_Context *ctx = JAR_find (jar, NULL, jarTypeOwner);
+ JAR_Context *ctx = JAR_find(jar, NULL, jarTypeOwner);
JAR_Signer *candidate;
JAR_Signer *signer = NULL;
if (ctx == NULL)
- return NULL;
-
- while (JAR_find_next (ctx, &it) >= 0) {
- candidate = (JAR_Signer *) it->data;
- if (*basename == '*' || !PORT_Strcmp (candidate->owner, basename)) {
- signer = candidate;
- break;
- }
+ return NULL;
+
+ while (JAR_find_next(ctx, &it) >= 0) {
+ candidate = (JAR_Signer *)it->data;
+ if (*basename == '*' || !PORT_Strcmp(candidate->owner, basename)) {
+ signer = candidate;
+ break;
+ }
}
- JAR_find_end (ctx);
+ JAR_find_end(ctx);
return signer;
}
@@ -567,12 +568,12 @@ JAR_get_url(JAR *jar)
* Register some manner of callback function for this jar.
*
*/
-int
+int
JAR_set_callback(int type, JAR *jar, jar_settable_callback_fn *fn)
{
if (type == JAR_CB_SIGNAL) {
- jar->signal = fn;
- return 0;
+ jar->signal = fn;
+ return 0;
}
return -1;
}
@@ -583,16 +584,16 @@ JAR_set_callback(int type, JAR *jar, jar_settable_callback_fn *fn)
*/
/* To return an error string */
-char *(*jar_fn_GetString) (int) = NULL;
+char *(*jar_fn_GetString)(int) = NULL;
/* To return an MWContext for Java */
-void *(*jar_fn_FindSomeContext) (void) = NULL;
+void *(*jar_fn_FindSomeContext)(void) = NULL;
/* To fabricate an MWContext for FE_GetPassword */
-void *(*jar_fn_GetInitContext) (void) = NULL;
+void *(*jar_fn_GetInitContext)(void) = NULL;
void
-JAR_init_callbacks(char *(*string_cb)(int),
+JAR_init_callbacks(char *(*string_cb)(int),
void *(*find_cx)(void),
void *(*init_cx)(void))
{
@@ -617,68 +618,68 @@ JAR_get_error(int status)
char *errstring = NULL;
switch (status) {
- case JAR_ERR_GENERAL:
- errstring = "General JAR file error";
- break;
-
- case JAR_ERR_FNF:
- errstring = "JAR file not found";
- break;
-
- case JAR_ERR_CORRUPT:
- errstring = "Corrupt JAR file";
- break;
-
- case JAR_ERR_MEMORY:
- errstring = "Out of memory";
- break;
-
- case JAR_ERR_DISK:
- errstring = "Disk error (perhaps out of space)";
- break;
-
- case JAR_ERR_ORDER:
- errstring = "Inconsistent files in META-INF directory";
- break;
-
- case JAR_ERR_SIG:
- errstring = "Invalid digital signature file";
- break;
-
- case JAR_ERR_METADATA:
- errstring = "JAR metadata failed verification";
- break;
-
- case JAR_ERR_ENTRY:
- errstring = "No Manifest entry for this JAR entry";
- break;
-
- case JAR_ERR_HASH:
- errstring = "Invalid Hash of this JAR entry";
- break;
-
- case JAR_ERR_PK7:
- errstring = "Strange PKCS7 or RSA failure";
- break;
-
- case JAR_ERR_PNF:
- errstring = "Path not found inside JAR file";
- break;
-
- default:
- if (jar_fn_GetString) {
- errstring = jar_fn_GetString (status);
- } else {
- /* this is not a normal situation, and would only be
+ case JAR_ERR_GENERAL:
+ errstring = "General JAR file error";
+ break;
+
+ case JAR_ERR_FNF:
+ errstring = "JAR file not found";
+ break;
+
+ case JAR_ERR_CORRUPT:
+ errstring = "Corrupt JAR file";
+ break;
+
+ case JAR_ERR_MEMORY:
+ errstring = "Out of memory";
+ break;
+
+ case JAR_ERR_DISK:
+ errstring = "Disk error (perhaps out of space)";
+ break;
+
+ case JAR_ERR_ORDER:
+ errstring = "Inconsistent files in META-INF directory";
+ break;
+
+ case JAR_ERR_SIG:
+ errstring = "Invalid digital signature file";
+ break;
+
+ case JAR_ERR_METADATA:
+ errstring = "JAR metadata failed verification";
+ break;
+
+ case JAR_ERR_ENTRY:
+ errstring = "No Manifest entry for this JAR entry";
+ break;
+
+ case JAR_ERR_HASH:
+ errstring = "Invalid Hash of this JAR entry";
+ break;
+
+ case JAR_ERR_PK7:
+ errstring = "Strange PKCS7 or RSA failure";
+ break;
+
+ case JAR_ERR_PNF:
+ errstring = "Path not found inside JAR file";
+ break;
+
+ default:
+ if (jar_fn_GetString) {
+ errstring = jar_fn_GetString(status);
+ } else {
+ /* this is not a normal situation, and would only be
called in cases of improper initialization */
- char *err = (char*)PORT_Alloc (40);
- if (err)
- PR_snprintf (err, 39, "Error %d\n", status); /* leak me! */
- else
- err = "Error! Bad! Out of memory!";
- return err;
- }
- break;
+ char *err = (char *)PORT_Alloc(40);
+ if (err)
+ PR_snprintf(err, 39, "Error %d\n", status); /* leak me! */
+ else
+ err = "Error! Bad! Out of memory!";
+ return err;
+ }
+ break;
}
return errstring;
}
diff --git a/lib/jar/jar.h b/lib/jar/jar.h
index 881556050..d337cef37 100644
--- a/lib/jar/jar.h
+++ b/lib/jar/jar.h
@@ -36,10 +36,10 @@ typedef enum {
/* void data in ZZList's contain JAR_Item type */
typedef struct JAR_Item_ {
- char *pathname; /* relative. inside zip file */
- jarType type; /* various types */
- size_t size; /* size of data below */
- void *data; /* totally opaque */
+ char *pathname; /* relative. inside zip file */
+ jarType type; /* various types */
+ size_t size; /* size of data below */
+ void *data; /* totally opaque */
} JAR_Item;
/* hashes */
@@ -51,9 +51,9 @@ typedef enum {
typedef struct JAR_Digest_ {
jarHash md5_status;
- unsigned char md5 [MD5_LENGTH];
+ unsigned char md5[MD5_LENGTH];
jarHash sha1_status;
- unsigned char sha1 [SHA1_LENGTH];
+ unsigned char sha1[SHA1_LENGTH];
} JAR_Digest;
/* physical archive formats */
@@ -68,35 +68,35 @@ typedef enum {
struct JAR_;
-typedef int jar_settable_callback_fn(int status, struct JAR_ *jar,
- const char *metafile, char *pathname,
- char *errortext);
+typedef int jar_settable_callback_fn(int status, struct JAR_ *jar,
+ const char *metafile, char *pathname,
+ char *errortext);
/* jar object */
typedef struct JAR_ {
- jarArch format; /* physical archive format */
+ jarArch format; /* physical archive format */
- char *url; /* Where it came from */
- char *filename; /* Disk location */
- FILE *fp; /* For multiple extractions */
+ char *url; /* Where it came from */
+ char *filename; /* Disk location */
+ FILE *fp; /* For multiple extractions */
/* JAR_FILE */
/* various linked lists */
- ZZList *manifest; /* Digests of MF sections */
- ZZList *hashes; /* Digests of actual signed files */
- ZZList *phy; /* Physical layout of JAR file */
- ZZList *metainfo; /* Global metainfo */
+ ZZList *manifest; /* Digests of MF sections */
+ ZZList *hashes; /* Digests of actual signed files */
+ ZZList *phy; /* Physical layout of JAR file */
+ ZZList *metainfo; /* Global metainfo */
- JAR_Digest *globalmeta; /* digest of .MF global portion */
+ JAR_Digest *globalmeta; /* digest of .MF global portion */
/* Below will change to a linked list to support multiple sigs */
- int pkcs7; /* Enforced opaqueness */
- int valid; /* PKCS7 signature validated */
+ int pkcs7; /* Enforced opaqueness */
+ int valid; /* PKCS7 signature validated */
- ZZList *signers; /* the above, per signer */
+ ZZList *signers; /* the above, per signer */
/* Window context, very necessary for PKCS11 now */
- void *mw; /* MWContext window context */
+ void *mw; /* MWContext window context */
/* Signal callback function */
jar_settable_callback_fn *signal;
@@ -111,20 +111,20 @@ typedef struct JAR_ {
*
*/
typedef struct JAR_Context_ {
- JAR *jar; /* Jar we are searching */
- char *pattern; /* Regular expression */
- jarType finding; /* Type of item to find */
- ZZLink *next; /* Next item in find */
- ZZLink *nextsign; /* Next signer, sometimes */
+ JAR *jar; /* Jar we are searching */
+ char *pattern; /* Regular expression */
+ jarType finding; /* Type of item to find */
+ ZZLink *next; /* Next item in find */
+ ZZLink *nextsign; /* Next signer, sometimes */
} JAR_Context;
typedef struct JAR_Signer_ {
- int pkcs7; /* Enforced opaqueness */
- int valid; /* PKCS7 signature validated */
- char *owner; /* name of .RSA file */
- JAR_Digest *digest; /* of .SF file */
- ZZList *sf; /* Linked list of .SF file contents */
- ZZList *certs; /* Signing information */
+ int pkcs7; /* Enforced opaqueness */
+ int valid; /* PKCS7 signature validated */
+ char *owner; /* name of .RSA file */
+ JAR_Digest *digest; /* of .SF file */
+ ZZList *sf; /* Linked list of .SF file contents */
+ ZZList *certs; /* Signing information */
} JAR_Signer;
/* Meta informaton, or "policy", from the manifest file.
@@ -151,7 +151,6 @@ typedef struct JAR_Cert_ {
CERTCertificate *cert;
} JAR_Cert;
-
/* certificate stuff */
typedef enum {
jarCertCompany = 1,
@@ -164,7 +163,7 @@ typedef enum {
} jarCert;
/* callback types */
-#define JAR_CB_SIGNAL 1
+#define JAR_CB_SIGNAL 1
/*
* This is the base for the JAR error codes. It will
@@ -173,40 +172,40 @@ typedef enum {
*
*/
#ifndef SEC_ERR_BASE
-#define SEC_ERR_BASE (-0x2000)
+#define SEC_ERR_BASE (-0x2000)
#endif
-#define JAR_BASE SEC_ERR_BASE + 300
+#define JAR_BASE SEC_ERR_BASE + 300
/* Jar specific error definitions */
-#define JAR_ERR_GENERAL (JAR_BASE + 1)
-#define JAR_ERR_FNF (JAR_BASE + 2)
-#define JAR_ERR_CORRUPT (JAR_BASE + 3)
-#define JAR_ERR_MEMORY (JAR_BASE + 4)
-#define JAR_ERR_DISK (JAR_BASE + 5)
-#define JAR_ERR_ORDER (JAR_BASE + 6)
-#define JAR_ERR_SIG (JAR_BASE + 7)
-#define JAR_ERR_METADATA (JAR_BASE + 8)
-#define JAR_ERR_ENTRY (JAR_BASE + 9)
-#define JAR_ERR_HASH (JAR_BASE + 10)
-#define JAR_ERR_PK7 (JAR_BASE + 11)
-#define JAR_ERR_PNF (JAR_BASE + 12)
+#define JAR_ERR_GENERAL (JAR_BASE + 1)
+#define JAR_ERR_FNF (JAR_BASE + 2)
+#define JAR_ERR_CORRUPT (JAR_BASE + 3)
+#define JAR_ERR_MEMORY (JAR_BASE + 4)
+#define JAR_ERR_DISK (JAR_BASE + 5)
+#define JAR_ERR_ORDER (JAR_BASE + 6)
+#define JAR_ERR_SIG (JAR_BASE + 7)
+#define JAR_ERR_METADATA (JAR_BASE + 8)
+#define JAR_ERR_ENTRY (JAR_BASE + 9)
+#define JAR_ERR_HASH (JAR_BASE + 10)
+#define JAR_ERR_PK7 (JAR_BASE + 11)
+#define JAR_ERR_PNF (JAR_BASE + 12)
/* Function declarations */
-extern JAR *JAR_new (void);
+extern JAR *JAR_new(void);
-extern void PR_CALLBACK JAR_destroy (JAR *jar);
+extern void PR_CALLBACK JAR_destroy(JAR *jar);
-extern char *JAR_get_error (int status);
+extern char *JAR_get_error(int status);
extern int JAR_set_callback(int type, JAR *jar, jar_settable_callback_fn *fn);
-extern void
-JAR_init_callbacks(char *(*string_cb)(int),
- void *(*find_cx)(void),
- void *(*init_cx)(void) );
+extern void
+JAR_init_callbacks(char *(*string_cb)(int),
+ void *(*find_cx)(void),
+ void *(*init_cx)(void));
/*
* JAR_set_context
@@ -220,7 +219,7 @@ JAR_init_callbacks(char *(*string_cb)(int),
* and one will be chosen for you.
*
*/
-int JAR_set_context (JAR *jar, void /*MWContext*/ *mw);
+int JAR_set_context(JAR *jar, void /*MWContext*/ *mw);
/*
* Iterative operations
@@ -236,17 +235,17 @@ int JAR_set_context (JAR *jar, void /*MWContext*/ *mw);
* JAR_Item *item;
* JAR_find (jar, "*.class", jarTypeMF);
* while (JAR_find_next (jar, &item) >= 0)
- * { do stuff }
+ * { do stuff }
*
*/
/* Replacement functions with an external context */
-extern JAR_Context *JAR_find (JAR *jar, char *pattern, jarType type);
+extern JAR_Context *JAR_find(JAR *jar, char *pattern, jarType type);
-extern int JAR_find_next (JAR_Context *ctx, JAR_Item **it);
+extern int JAR_find_next(JAR_Context *ctx, JAR_Item **it);
-extern void JAR_find_end (JAR_Context *ctx);
+extern void JAR_find_end(JAR_Context *ctx);
/*
* Function to parse manifest file:
@@ -273,7 +272,7 @@ extern void JAR_find_end (JAR_Context *ctx);
*
*/
-extern int
+extern int
JAR_parse_manifest(JAR *jar, char *raw_manifest, long length, const char *path,
const char *url);
@@ -283,13 +282,13 @@ JAR_parse_manifest(JAR *jar, char *raw_manifest, long length, const char *path,
*
*/
-extern JAR_Digest * PR_CALLBACK
+extern JAR_Digest *PR_CALLBACK
JAR_calculate_digest(void *data, long length);
-extern int PR_CALLBACK
+extern int PR_CALLBACK
JAR_verify_digest(JAR *jar, const char *name, JAR_Digest *dig);
-extern int
+extern int
JAR_digest_file(char *filename, JAR_Digest *dig);
/*
@@ -309,18 +308,18 @@ JAR_digest_file(char *filename, JAR_Digest *dig);
*
*/
-extern int
-JAR_get_metainfo(JAR *jar, char *name, char *header, void **info,
+extern int
+JAR_get_metainfo(JAR *jar, char *name, char *header, void **info,
unsigned long *length);
-extern char *JAR_get_filename (JAR *jar);
+extern char *JAR_get_filename(JAR *jar);
-extern char *JAR_get_url (JAR *jar);
+extern char *JAR_get_url(JAR *jar);
/* save the certificate with this fingerprint in persistent
storage, somewhere, for retrieval in a future session when there
is no corresponding JAR structure. */
-extern int PR_CALLBACK
+extern int PR_CALLBACK
JAR_stash_cert(JAR *jar, long keylen, void *key);
/* retrieve a certificate presumably stashed with the above
@@ -341,14 +340,14 @@ JAR_fetch_cert(long length, void *key);
* a list of filenames and certificates from traversing the linked list.
*
*/
-extern int
+extern int
JAR_pass_archive(JAR *jar, jarArch format, char *filename, const char *url);
/*
* Same thing, but don't check signatures
*/
-extern int
-JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename,
+extern int
+JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename,
const char *url);
/*
@@ -359,7 +358,7 @@ JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename,
* open between multiple calls to JAR_verify_extract.
*
*/
-extern int
+extern int
JAR_verified_extract(JAR *jar, char *path, char *outpath);
/*
@@ -367,7 +366,7 @@ JAR_verified_extract(JAR *jar, char *path, char *outpath);
* need to extract a manifest file or signature, etc.
*
*/
-extern int
+extern int
JAR_extract(JAR *jar, char *path, char *outpath);
#endif /* __JAR_h_ */
diff --git a/lib/jar/jarfile.c b/lib/jar/jarfile.c
index 96da4d793..242e6d797 100644
--- a/lib/jar/jarfile.c
+++ b/lib/jar/jarfile.c
@@ -20,7 +20,7 @@
#include "sys/stat.h"
#endif
-#include "sechash.h" /* for HASH_GetHashObject() */
+#include "sechash.h" /* for HASH_GetHashObject() */
PR_STATIC_ASSERT(46 == sizeof(struct ZipCentral));
PR_STATIC_ASSERT(30 == sizeof(struct ZipLocal));
@@ -28,50 +28,48 @@ PR_STATIC_ASSERT(22 == sizeof(struct ZipEnd));
PR_STATIC_ASSERT(512 == sizeof(union TarEntry));
/* extracting */
-static int
+static int
jar_guess_jar(const char *filename, JAR_FILE fp);
-static int
-jar_inflate_memory(unsigned int method, long *length, long expected_out_len,
+static int
+jar_inflate_memory(unsigned int method, long *length, long expected_out_len,
char **data);
-static int
+static int
jar_physical_extraction(JAR_FILE fp, char *outpath, unsigned long offset,
unsigned long length);
-static int
+static int
jar_physical_inflate(JAR_FILE fp, char *outpath, unsigned long offset,
unsigned long length, unsigned int method);
-static int
+static int
jar_verify_extract(JAR *jar, char *path, char *physical_path);
static JAR_Physical *
jar_get_physical(JAR *jar, char *pathname);
-static int
+static int
jar_extract_manifests(JAR *jar, jarArch format, JAR_FILE fp);
-static int
+static int
jar_extract_mf(JAR *jar, jarArch format, JAR_FILE fp, char *ext);
-
/* indexing */
-static int
+static int
jar_gen_index(JAR *jar, jarArch format, JAR_FILE fp);
-static int
+static int
jar_listtar(JAR *jar, JAR_FILE fp);
-static int
+static int
jar_listzip(JAR *jar, JAR_FILE fp);
-
/* conversions */
-static int
+static int
dosdate(char *date, const char *s);
-static int
+static int
dostime(char *time, const char *s);
#ifdef NSS_X86_OR_X64
@@ -79,8 +77,8 @@ dostime(char *time, const char *s);
#if defined(__GNUC__) && !defined(NSS_NO_GCC48)
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
-#define x86ShortToUint32(ii) ((const PRUint32)*((const PRUint16 *)(ii)))
-#define x86LongToUint32(ii) (*(const PRUint32 *)(ii))
+#define x86ShortToUint32(ii) ((const PRUint32) * ((const PRUint16 *)(ii)))
+#define x86LongToUint32(ii) (*(const PRUint32 *)(ii))
#else
static PRUint32
x86ShortToUint32(const void *ii);
@@ -89,7 +87,7 @@ static PRUint32
x86LongToUint32(const void *ll);
#endif
-static long
+static long
octalToLong(const char *s);
/*
@@ -100,33 +98,33 @@ octalToLong(const char *s);
* the archive file, and do whatever nastiness.
*
*/
-int
+int
JAR_pass_archive(JAR *jar, jarArch format, char *filename, const char *url)
{
JAR_FILE fp;
int status = 0;
if (filename == NULL)
- return JAR_ERR_GENERAL;
+ return JAR_ERR_GENERAL;
- if ((fp = JAR_FOPEN (filename, "rb")) != NULL) {
- if (format == jarArchGuess)
- format = (jarArch)jar_guess_jar (filename, fp);
+ if ((fp = JAR_FOPEN(filename, "rb")) != NULL) {
+ if (format == jarArchGuess)
+ format = (jarArch)jar_guess_jar(filename, fp);
- jar->format = format;
- jar->url = url ? PORT_Strdup (url) : NULL;
- jar->filename = PORT_Strdup (filename);
+ jar->format = format;
+ jar->url = url ? PORT_Strdup(url) : NULL;
+ jar->filename = PORT_Strdup(filename);
- status = jar_gen_index (jar, format, fp);
- if (status == 0)
- status = jar_extract_manifests (jar, format, fp);
+ status = jar_gen_index(jar, format, fp);
+ if (status == 0)
+ status = jar_extract_manifests(jar, format, fp);
- JAR_FCLOSE (fp);
- if (status < 0)
- return status;
+ JAR_FCLOSE(fp);
+ if (status < 0)
+ return status;
- /* people were expecting it this way */
- return jar->valid;
+ /* people were expecting it this way */
+ return jar->valid;
}
/* file not found */
return JAR_ERR_FNF;
@@ -138,38 +136,38 @@ JAR_pass_archive(JAR *jar, jarArch format, char *filename, const char *url)
* Same as JAR_pass_archive, but doesn't parse signatures.
*
*/
-int
-JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename,
+int
+JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename,
const char *url)
{
JAR_FILE fp;
int status = 0;
if (filename == NULL) {
- return JAR_ERR_GENERAL;
+ return JAR_ERR_GENERAL;
}
- if ((fp = JAR_FOPEN (filename, "rb")) != NULL) {
- if (format == jarArchGuess) {
- format = (jarArch)jar_guess_jar (filename, fp);
- }
+ if ((fp = JAR_FOPEN(filename, "rb")) != NULL) {
+ if (format == jarArchGuess) {
+ format = (jarArch)jar_guess_jar(filename, fp);
+ }
- jar->format = format;
- jar->url = url ? PORT_Strdup (url) : NULL;
- jar->filename = PORT_Strdup (filename);
+ jar->format = format;
+ jar->url = url ? PORT_Strdup(url) : NULL;
+ jar->filename = PORT_Strdup(filename);
- status = jar_gen_index (jar, format, fp);
- if (status == 0) {
- status = jar_extract_mf(jar, format, fp, "mf");
- }
+ status = jar_gen_index(jar, format, fp);
+ if (status == 0) {
+ status = jar_extract_mf(jar, format, fp, "mf");
+ }
- JAR_FCLOSE (fp);
- if (status < 0) {
- return status;
- }
+ JAR_FCLOSE(fp);
+ if (status < 0) {
+ return status;
+ }
- /* people were expecting it this way */
- return jar->valid;
+ /* people were expecting it this way */
+ return jar->valid;
}
/* file not found */
return JAR_ERR_FNF;
@@ -184,52 +182,51 @@ JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename,
*
*/
-int
+int
JAR_verified_extract(JAR *jar, char *path, char *outpath)
{
- int status = JAR_extract (jar, path, outpath);
+ int status = JAR_extract(jar, path, outpath);
if (status >= 0)
- return jar_verify_extract(jar, path, outpath);
+ return jar_verify_extract(jar, path, outpath);
return status;
}
-int
+int
JAR_extract(JAR *jar, char *path, char *outpath)
{
int result;
JAR_Physical *phy;
if (jar->fp == NULL && jar->filename) {
- jar->fp = (FILE*)JAR_FOPEN (jar->filename, "rb");
+ jar->fp = (FILE *)JAR_FOPEN(jar->filename, "rb");
}
if (jar->fp == NULL) {
- /* file not found */
- return JAR_ERR_FNF;
+ /* file not found */
+ return JAR_ERR_FNF;
}
- phy = jar_get_physical (jar, path);
+ phy = jar_get_physical(jar, path);
if (phy) {
- if (phy->compression != 0 && phy->compression != 8) {
- /* unsupported compression method */
- result = JAR_ERR_CORRUPT;
- }
- if (phy->compression == 0) {
- result = jar_physical_extraction
- ((PRFileDesc*)jar->fp, outpath, phy->offset, phy->length);
- } else {
- result = jar_physical_inflate((PRFileDesc*)jar->fp, outpath,
- phy->offset, phy->length,
- (unsigned int) phy->compression);
- }
+ if (phy->compression != 0 && phy->compression != 8) {
+ /* unsupported compression method */
+ result = JAR_ERR_CORRUPT;
+ }
+ if (phy->compression == 0) {
+ result = jar_physical_extraction((PRFileDesc *)jar->fp, outpath, phy->offset, phy->length);
+ } else {
+ result = jar_physical_inflate((PRFileDesc *)jar->fp, outpath,
+ phy->offset, phy->length,
+ (unsigned int)phy->compression);
+ }
#if defined(XP_UNIX) || defined(XP_BEOS)
- if (phy->mode)
- chmod (outpath, 0400 | (mode_t) phy->mode);
+ if (phy->mode)
+ chmod(outpath, 0400 | (mode_t)phy->mode);
#endif
} else {
- /* pathname not found in archive */
- result = JAR_ERR_PNF;
+ /* pathname not found in archive */
+ result = JAR_ERR_PNF;
}
return result;
}
@@ -245,7 +242,7 @@ JAR_extract(JAR *jar, char *path, char *outpath)
#define CHUNK 32768
-static int
+static int
jar_physical_extraction(JAR_FILE fp, char *outpath, unsigned long offset,
unsigned long length)
{
@@ -254,31 +251,31 @@ jar_physical_extraction(JAR_FILE fp, char *outpath, unsigned long offset,
int status = 0;
if (buffer == NULL)
- return JAR_ERR_MEMORY;
-
- if ((out = JAR_FOPEN (outpath, "wb")) != NULL) {
- unsigned long at = 0;
-
- JAR_FSEEK (fp, offset, (PRSeekWhence)0);
- while (at < length) {
- long chunk = (at + CHUNK <= length) ? CHUNK : length - at;
- if (JAR_FREAD (fp, buffer, chunk) != chunk) {
- status = JAR_ERR_DISK;
- break;
- }
- at += chunk;
- if (JAR_FWRITE (out, buffer, chunk) < chunk) {
- /* most likely a disk full error */
- status = JAR_ERR_DISK;
- break;
- }
- }
- JAR_FCLOSE (out);
+ return JAR_ERR_MEMORY;
+
+ if ((out = JAR_FOPEN(outpath, "wb")) != NULL) {
+ unsigned long at = 0;
+
+ JAR_FSEEK(fp, offset, (PRSeekWhence)0);
+ while (at < length) {
+ long chunk = (at + CHUNK <= length) ? CHUNK : length - at;
+ if (JAR_FREAD(fp, buffer, chunk) != chunk) {
+ status = JAR_ERR_DISK;
+ break;
+ }
+ at += chunk;
+ if (JAR_FWRITE(out, buffer, chunk) < chunk) {
+ /* most likely a disk full error */
+ status = JAR_ERR_DISK;
+ break;
+ }
+ }
+ JAR_FCLOSE(out);
} else {
- /* error opening output file */
- status = JAR_ERR_DISK;
+ /* error opening output file */
+ status = JAR_ERR_DISK;
}
- PORT_Free (buffer);
+ PORT_Free(buffer);
return status;
}
@@ -294,7 +291,7 @@ jar_physical_extraction(JAR_FILE fp, char *outpath, unsigned long offset,
#define ICHUNK 8192
#define OCHUNK 32768
-static int
+static int
jar_physical_inflate(JAR_FILE fp, char *outpath, unsigned long offset, unsigned long length,
unsigned int method)
{
@@ -305,77 +302,77 @@ jar_physical_inflate(JAR_FILE fp, char *outpath, unsigned long offset, unsigned
/* Raw inflate in zlib 1.1.4 needs an extra dummy byte at the end */
if ((inbuf = (char *)PORT_ZAlloc(ICHUNK + 1)) == NULL)
- return JAR_ERR_MEMORY;
+ return JAR_ERR_MEMORY;
if ((outbuf = (char *)PORT_ZAlloc(OCHUNK)) == NULL) {
- PORT_Free (inbuf);
- return JAR_ERR_MEMORY;
+ PORT_Free(inbuf);
+ return JAR_ERR_MEMORY;
}
- PORT_Memset (&zs, 0, sizeof (zs));
- status = inflateInit2 (&zs, -MAX_WBITS);
+ PORT_Memset(&zs, 0, sizeof(zs));
+ status = inflateInit2(&zs, -MAX_WBITS);
if (status != Z_OK) {
- PORT_Free (inbuf);
- PORT_Free (outbuf);
- return JAR_ERR_GENERAL;
+ PORT_Free(inbuf);
+ PORT_Free(outbuf);
+ return JAR_ERR_GENERAL;
}
- if ((out = JAR_FOPEN (outpath, "wb")) != NULL) {
- unsigned long at = 0;
-
- JAR_FSEEK (fp, offset, (PRSeekWhence)0);
- while (at < length) {
- unsigned long chunk = (at + ICHUNK <= length) ? ICHUNK : length - at;
- unsigned long tin;
-
- if (JAR_FREAD (fp, inbuf, chunk) != chunk) {
- /* incomplete read */
- JAR_FCLOSE (out);
- PORT_Free (inbuf);
- PORT_Free (outbuf);
- return JAR_ERR_CORRUPT;
- }
- at += chunk;
- if (at == length) {
- /* add an extra dummy byte at the end */
- inbuf[chunk++] = 0xDD;
- }
- zs.next_in = (Bytef *) inbuf;
- zs.avail_in = chunk;
- zs.avail_out = OCHUNK;
- tin = zs.total_in;
- while ((zs.total_in - tin < chunk) || (zs.avail_out == 0)) {
- unsigned long prev_total = zs.total_out;
- unsigned long ochunk;
-
- zs.next_out = (Bytef *) outbuf;
- zs.avail_out = OCHUNK;
- status = inflate (&zs, Z_NO_FLUSH);
- if (status != Z_OK && status != Z_STREAM_END) {
- /* error during decompression */
- JAR_FCLOSE (out);
- PORT_Free (inbuf);
- PORT_Free (outbuf);
- return JAR_ERR_CORRUPT;
- }
- ochunk = zs.total_out - prev_total;
- if (JAR_FWRITE (out, outbuf, ochunk) < (long)ochunk) {
- /* most likely a disk full error */
- status = JAR_ERR_DISK;
- break;
- }
- if (status == Z_STREAM_END)
- break;
- }
- }
- JAR_FCLOSE (out);
- status = inflateEnd (&zs);
+ if ((out = JAR_FOPEN(outpath, "wb")) != NULL) {
+ unsigned long at = 0;
+
+ JAR_FSEEK(fp, offset, (PRSeekWhence)0);
+ while (at < length) {
+ unsigned long chunk = (at + ICHUNK <= length) ? ICHUNK : length - at;
+ unsigned long tin;
+
+ if (JAR_FREAD(fp, inbuf, chunk) != chunk) {
+ /* incomplete read */
+ JAR_FCLOSE(out);
+ PORT_Free(inbuf);
+ PORT_Free(outbuf);
+ return JAR_ERR_CORRUPT;
+ }
+ at += chunk;
+ if (at == length) {
+ /* add an extra dummy byte at the end */
+ inbuf[chunk++] = 0xDD;
+ }
+ zs.next_in = (Bytef *)inbuf;
+ zs.avail_in = chunk;
+ zs.avail_out = OCHUNK;
+ tin = zs.total_in;
+ while ((zs.total_in - tin < chunk) || (zs.avail_out == 0)) {
+ unsigned long prev_total = zs.total_out;
+ unsigned long ochunk;
+
+ zs.next_out = (Bytef *)outbuf;
+ zs.avail_out = OCHUNK;
+ status = inflate(&zs, Z_NO_FLUSH);
+ if (status != Z_OK && status != Z_STREAM_END) {
+ /* error during decompression */
+ JAR_FCLOSE(out);
+ PORT_Free(inbuf);
+ PORT_Free(outbuf);
+ return JAR_ERR_CORRUPT;
+ }
+ ochunk = zs.total_out - prev_total;
+ if (JAR_FWRITE(out, outbuf, ochunk) < (long)ochunk) {
+ /* most likely a disk full error */
+ status = JAR_ERR_DISK;
+ break;
+ }
+ if (status == Z_STREAM_END)
+ break;
+ }
+ }
+ JAR_FCLOSE(out);
+ status = inflateEnd(&zs);
} else {
- /* error opening output file */
- status = JAR_ERR_DISK;
+ /* error opening output file */
+ status = JAR_ERR_DISK;
}
- PORT_Free (inbuf);
- PORT_Free (outbuf);
+ PORT_Free(inbuf);
+ PORT_Free(outbuf);
return status;
}
@@ -386,44 +383,44 @@ jar_physical_inflate(JAR_FILE fp, char *outpath, unsigned long offset, unsigned
* and thus appears to operate inplace to the caller.
*
*/
-static int
-jar_inflate_memory(unsigned int method, long *length, long expected_out_len,
+static int
+jar_inflate_memory(unsigned int method, long *length, long expected_out_len,
char **data)
{
- char *inbuf = *data;
- char *outbuf = (char*)PORT_ZAlloc(expected_out_len);
- long insz = *length;
+ char *inbuf = *data;
+ char *outbuf = (char *)PORT_ZAlloc(expected_out_len);
+ long insz = *length;
int status;
z_stream zs;
if (outbuf == NULL)
- return JAR_ERR_MEMORY;
+ return JAR_ERR_MEMORY;
PORT_Memset(&zs, 0, sizeof zs);
- status = inflateInit2 (&zs, -MAX_WBITS);
+ status = inflateInit2(&zs, -MAX_WBITS);
if (status < 0) {
- /* error initializing zlib stream */
- PORT_Free (outbuf);
- return JAR_ERR_GENERAL;
+ /* error initializing zlib stream */
+ PORT_Free(outbuf);
+ return JAR_ERR_GENERAL;
}
- zs.next_in = (Bytef *) inbuf;
- zs.next_out = (Bytef *) outbuf;
+ zs.next_in = (Bytef *)inbuf;
+ zs.next_out = (Bytef *)outbuf;
zs.avail_in = insz;
zs.avail_out = expected_out_len;
- status = inflate (&zs, Z_FINISH);
+ status = inflate(&zs, Z_FINISH);
if (status != Z_OK && status != Z_STREAM_END) {
- /* error during deflation */
- PORT_Free (outbuf);
- return JAR_ERR_GENERAL;
+ /* error during deflation */
+ PORT_Free(outbuf);
+ return JAR_ERR_GENERAL;
}
- status = inflateEnd (&zs);
+ status = inflateEnd(&zs);
if (status != Z_OK) {
- /* error during deflation */
- PORT_Free (outbuf);
- return JAR_ERR_GENERAL;
+ /* error during deflation */
+ PORT_Free(outbuf);
+ return JAR_ERR_GENERAL;
}
PORT_Free(*data);
*data = outbuf;
@@ -437,16 +434,16 @@ jar_inflate_memory(unsigned int method, long *length, long expected_out_len,
* Validate signature on the freshly extracted file.
*
*/
-static int
+static int
jar_verify_extract(JAR *jar, char *path, char *physical_path)
{
int status;
JAR_Digest dig;
- PORT_Memset (&dig, 0, sizeof dig);
- status = JAR_digest_file (physical_path, &dig);
+ PORT_Memset(&dig, 0, sizeof dig);
+ status = JAR_digest_file(physical_path, &dig);
if (!status)
- status = JAR_verify_digest (jar, path, &dig);
+ status = JAR_verify_digest(jar, path, &dig);
return status;
}
@@ -463,19 +460,19 @@ jar_get_physical(JAR *jar, char *pathname)
ZZLink *link;
ZZList *list = jar->phy;
- if (ZZ_ListEmpty (list))
- return NULL;
+ if (ZZ_ListEmpty(list))
+ return NULL;
- for (link = ZZ_ListHead (list);
- !ZZ_ListIterDone (list, link);
+ for (link = ZZ_ListHead(list);
+ !ZZ_ListIterDone(list, link);
link = link->next) {
- JAR_Item *it = link->thing;
+ JAR_Item *it = link->thing;
- if (it->type == jarTypePhy &&
- it->pathname && !PORT_Strcmp (it->pathname, pathname)) {
- JAR_Physical *phy = (JAR_Physical *)it->data;
- return phy;
- }
+ if (it->type == jarTypePhy &&
+ it->pathname && !PORT_Strcmp(it->pathname, pathname)) {
+ JAR_Physical *phy = (JAR_Physical *)it->data;
+ return phy;
+ }
}
return NULL;
}
@@ -487,29 +484,29 @@ jar_get_physical(JAR *jar, char *pathname)
* from an open archive file whose contents are known.
*
*/
-static int
+static int
jar_extract_manifests(JAR *jar, jarArch format, JAR_FILE fp)
{
int status, signatures;
if (format != jarArchZip && format != jarArchTar)
- return JAR_ERR_CORRUPT;
+ return JAR_ERR_CORRUPT;
- if ((status = jar_extract_mf (jar, format, fp, "mf")) < 0)
- return status;
+ if ((status = jar_extract_mf(jar, format, fp, "mf")) < 0)
+ return status;
if (!status)
- return JAR_ERR_ORDER;
- if ((status = jar_extract_mf (jar, format, fp, "sf")) < 0)
- return status;
+ return JAR_ERR_ORDER;
+ if ((status = jar_extract_mf(jar, format, fp, "sf")) < 0)
+ return status;
if (!status)
- return JAR_ERR_ORDER;
- if ((status = jar_extract_mf (jar, format, fp, "rsa")) < 0)
- return status;
+ return JAR_ERR_ORDER;
+ if ((status = jar_extract_mf(jar, format, fp, "rsa")) < 0)
+ return status;
signatures = status;
- if ((status = jar_extract_mf (jar, format, fp, "dsa")) < 0)
- return status;
+ if ((status = jar_extract_mf(jar, format, fp, "dsa")) < 0)
+ return status;
if (!(signatures += status))
- return JAR_ERR_SIG;
+ return JAR_ERR_SIG;
return 0;
}
@@ -521,101 +518,100 @@ jar_extract_manifests(JAR *jar, jarArch format, JAR_FILE fp)
* longer important when zipping jar files.
*
*/
-static int
+static int
jar_extract_mf(JAR *jar, jarArch format, JAR_FILE fp, char *ext)
{
ZZLink *link;
ZZList *list = jar->phy;
int ret = 0;
- if (ZZ_ListEmpty (list))
- return JAR_ERR_PNF;
+ if (ZZ_ListEmpty(list))
+ return JAR_ERR_PNF;
- for (link = ZZ_ListHead (list);
- ret >= 0 && !ZZ_ListIterDone (list, link);
+ for (link = ZZ_ListHead(list);
+ ret >= 0 && !ZZ_ListIterDone(list, link);
link = link->next) {
- JAR_Item *it = link->thing;
-
- if (it->type == jarTypePhy &&
- !PORT_Strncmp (it->pathname, "META-INF", 8))
- {
- JAR_Physical *phy = (JAR_Physical *) it->data;
- char *fn = it->pathname + 8;
- char *e;
- char *manifest;
- long length;
- int num, status;
-
- if (PORT_Strlen (it->pathname) < 8)
- continue;
-
- if (*fn == '/' || *fn == '\\')
- fn++;
- if (*fn == 0) {
- /* just a directory entry */
- continue;
- }
-
- /* skip to extension */
- for (e = fn; *e && *e != '.'; e++)
- /* yip */ ;
-
- /* and skip dot */
- if (*e == '.')
- e++;
- if (PORT_Strcasecmp (ext, e)) {
- /* not the right extension */
- continue;
- }
- if (phy->length == 0 || phy->length > 0xFFFF) {
- /* manifest files cannot be zero length or too big! */
- /* the 0xFFFF limit is per J2SE SDK */
- return JAR_ERR_CORRUPT;
- }
-
- /* Read in the manifest and parse it */
- /* Raw inflate in zlib 1.1.4 needs an extra dummy byte at the end */
- manifest = (char *)PORT_ZAlloc(phy->length + 1);
- if (!manifest)
- return JAR_ERR_MEMORY;
-
- JAR_FSEEK (fp, phy->offset, (PRSeekWhence)0);
- num = JAR_FREAD (fp, manifest, phy->length);
- if (num != phy->length) {
- /* corrupt archive file */
- PORT_Free (manifest);
- return JAR_ERR_CORRUPT;
- }
-
- if (phy->compression == 8) {
- length = phy->length;
- /* add an extra dummy byte at the end */
- manifest[length++] = 0xDD;
- status = jar_inflate_memory((unsigned int)phy->compression,
- &length,
- phy->uncompressed_length,
- &manifest);
- if (status < 0) {
- PORT_Free (manifest);
- return status;
- }
- } else if (phy->compression) {
- /* unsupported compression method */
- PORT_Free (manifest);
- return JAR_ERR_CORRUPT;
- } else
- length = phy->length;
-
- status = JAR_parse_manifest(jar, manifest, length,
- it->pathname, "url");
- PORT_Free (manifest);
- if (status < 0)
- ret = status;
- else
- ++ret;
- } else if (it->type == jarTypePhy) {
- /* ordinary file */
- }
+ JAR_Item *it = link->thing;
+
+ if (it->type == jarTypePhy &&
+ !PORT_Strncmp(it->pathname, "META-INF", 8)) {
+ JAR_Physical *phy = (JAR_Physical *)it->data;
+ char *fn = it->pathname + 8;
+ char *e;
+ char *manifest;
+ long length;
+ int num, status;
+
+ if (PORT_Strlen(it->pathname) < 8)
+ continue;
+
+ if (*fn == '/' || *fn == '\\')
+ fn++;
+ if (*fn == 0) {
+ /* just a directory entry */
+ continue;
+ }
+
+ /* skip to extension */
+ for (e = fn; *e && *e != '.'; e++)
+ /* yip */;
+
+ /* and skip dot */
+ if (*e == '.')
+ e++;
+ if (PORT_Strcasecmp(ext, e)) {
+ /* not the right extension */
+ continue;
+ }
+ if (phy->length == 0 || phy->length > 0xFFFF) {
+ /* manifest files cannot be zero length or too big! */
+ /* the 0xFFFF limit is per J2SE SDK */
+ return JAR_ERR_CORRUPT;
+ }
+
+ /* Read in the manifest and parse it */
+ /* Raw inflate in zlib 1.1.4 needs an extra dummy byte at the end */
+ manifest = (char *)PORT_ZAlloc(phy->length + 1);
+ if (!manifest)
+ return JAR_ERR_MEMORY;
+
+ JAR_FSEEK(fp, phy->offset, (PRSeekWhence)0);
+ num = JAR_FREAD(fp, manifest, phy->length);
+ if (num != phy->length) {
+ /* corrupt archive file */
+ PORT_Free(manifest);
+ return JAR_ERR_CORRUPT;
+ }
+
+ if (phy->compression == 8) {
+ length = phy->length;
+ /* add an extra dummy byte at the end */
+ manifest[length++] = 0xDD;
+ status = jar_inflate_memory((unsigned int)phy->compression,
+ &length,
+ phy->uncompressed_length,
+ &manifest);
+ if (status < 0) {
+ PORT_Free(manifest);
+ return status;
+ }
+ } else if (phy->compression) {
+ /* unsupported compression method */
+ PORT_Free(manifest);
+ return JAR_ERR_CORRUPT;
+ } else
+ length = phy->length;
+
+ status = JAR_parse_manifest(jar, manifest, length,
+ it->pathname, "url");
+ PORT_Free(manifest);
+ if (status < 0)
+ ret = status;
+ else
+ ++ret;
+ } else if (it->type == jarTypePhy) {
+ /* ordinary file */
+ }
}
return ret;
}
@@ -627,26 +623,26 @@ jar_extract_mf(JAR *jar, jarArch format, JAR_FILE fp, char *ext)
* known archive files. Right now .ZIP and .TAR
*
*/
-static int
+static int
jar_gen_index(JAR *jar, jarArch format, JAR_FILE fp)
{
int result = JAR_ERR_CORRUPT;
- JAR_FSEEK (fp, 0, (PRSeekWhence)0);
+ JAR_FSEEK(fp, 0, (PRSeekWhence)0);
switch (format) {
- case jarArchZip:
- result = jar_listzip (jar, fp);
- break;
+ case jarArchZip:
+ result = jar_listzip(jar, fp);
+ break;
- case jarArchTar:
- result = jar_listtar (jar, fp);
- break;
+ case jarArchTar:
+ result = jar_listtar(jar, fp);
+ break;
- case jarArchGuess:
- case jarArchNone:
- return JAR_ERR_GENERAL;
+ case jarArchGuess:
+ case jarArchNone:
+ return JAR_ERR_GENERAL;
}
- JAR_FSEEK (fp, 0, (PRSeekWhence)0);
+ JAR_FSEEK(fp, 0, (PRSeekWhence)0);
return result;
}
@@ -657,15 +653,15 @@ jar_gen_index(JAR *jar, jarArch format, JAR_FILE fp)
* style .ZIP file into the JAR linked list.
*
*/
-static int
+static int
jar_listzip(JAR *jar, JAR_FILE fp)
{
- ZZLink *ent;
+ ZZLink *ent;
JAR_Item *it;
JAR_Physical *phy;
- struct ZipLocal *Local = PORT_ZNew(struct ZipLocal);
+ struct ZipLocal *Local = PORT_ZNew(struct ZipLocal);
struct ZipCentral *Central = PORT_ZNew(struct ZipCentral);
- struct ZipEnd *End = PORT_ZNew(struct ZipEnd);
+ struct ZipEnd *End = PORT_ZNew(struct ZipEnd);
int err = 0;
long pos = 0L;
@@ -677,139 +673,139 @@ jar_listzip(JAR *jar, JAR_FILE fp)
char sig[4];
if (!Local || !Central || !End) {
- /* out of memory */
- err = JAR_ERR_MEMORY;
- goto loser;
+ /* out of memory */
+ err = JAR_ERR_MEMORY;
+ goto loser;
}
while (1) {
- PRUint32 sigVal;
- JAR_FSEEK (fp, pos, (PRSeekWhence)0);
-
- if (JAR_FREAD(fp, sig, sizeof sig) != sizeof sig) {
- /* zip file ends prematurely */
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
-
- JAR_FSEEK (fp, pos, (PRSeekWhence)0);
- sigVal = x86LongToUint32(sig);
- if (sigVal == LSIG) {
- JAR_FREAD (fp, Local, sizeof *Local);
-
- filename_len = x86ShortToUint32(Local->filename_len);
- extra_len = x86ShortToUint32(Local->extrafield_len);
- if (filename_len >= JAR_SIZE) {
- /* corrupt zip file */
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
-
- if (JAR_FREAD (fp, filename, filename_len) != filename_len) {
- /* truncated archive file */
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
- filename [filename_len] = 0;
- /* Add this to our jar chain */
- phy = PORT_ZNew(JAR_Physical);
- if (phy == NULL) {
- err = JAR_ERR_MEMORY;
- goto loser;
- }
-
- /* We will index any file that comes our way, but when it comes
- to actually extraction, compression must be 0 or 8 */
- compression = x86ShortToUint32(Local->method);
- phy->compression = (compression <= 255) ? compression : 222;
- /* XXX 222 is bad magic. */
-
- phy->offset = pos + (sizeof *Local) + filename_len + extra_len;
- phy->length = x86LongToUint32(Local->size);
- phy->uncompressed_length = x86LongToUint32(Local->orglen);
-
- dosdate (date, Local->date);
- dostime (time, Local->time);
-
- it = PORT_ZNew(JAR_Item);
- if (it == NULL) {
- err = JAR_ERR_MEMORY;
- goto loser;
- }
-
- it->pathname = PORT_Strdup(filename);
- it->type = jarTypePhy;
- it->data = (unsigned char *) phy;
- it->size = sizeof (JAR_Physical);
-
- ent = ZZ_NewLink (it);
- if (ent == NULL) {
- err = JAR_ERR_MEMORY;
- goto loser;
- }
-
- ZZ_AppendLink (jar->phy, ent);
- pos = phy->offset + phy->length;
- } else if (sigVal == CSIG) {
- unsigned int attr = 0;
- if (JAR_FREAD(fp, Central, sizeof *Central) != sizeof *Central) {
- /* apparently truncated archive */
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
+ PRUint32 sigVal;
+ JAR_FSEEK(fp, pos, (PRSeekWhence)0);
+
+ if (JAR_FREAD(fp, sig, sizeof sig) != sizeof sig) {
+ /* zip file ends prematurely */
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
+
+ JAR_FSEEK(fp, pos, (PRSeekWhence)0);
+ sigVal = x86LongToUint32(sig);
+ if (sigVal == LSIG) {
+ JAR_FREAD(fp, Local, sizeof *Local);
+
+ filename_len = x86ShortToUint32(Local->filename_len);
+ extra_len = x86ShortToUint32(Local->extrafield_len);
+ if (filename_len >= JAR_SIZE) {
+ /* corrupt zip file */
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
+
+ if (JAR_FREAD(fp, filename, filename_len) != filename_len) {
+ /* truncated archive file */
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
+ filename[filename_len] = 0;
+ /* Add this to our jar chain */
+ phy = PORT_ZNew(JAR_Physical);
+ if (phy == NULL) {
+ err = JAR_ERR_MEMORY;
+ goto loser;
+ }
+
+ /* We will index any file that comes our way, but when it comes
+ to actually extraction, compression must be 0 or 8 */
+ compression = x86ShortToUint32(Local->method);
+ phy->compression = (compression <= 255) ? compression : 222;
+ /* XXX 222 is bad magic. */
+
+ phy->offset = pos + (sizeof *Local) + filename_len + extra_len;
+ phy->length = x86LongToUint32(Local->size);
+ phy->uncompressed_length = x86LongToUint32(Local->orglen);
+
+ dosdate(date, Local->date);
+ dostime(time, Local->time);
+
+ it = PORT_ZNew(JAR_Item);
+ if (it == NULL) {
+ err = JAR_ERR_MEMORY;
+ goto loser;
+ }
+
+ it->pathname = PORT_Strdup(filename);
+ it->type = jarTypePhy;
+ it->data = (unsigned char *)phy;
+ it->size = sizeof(JAR_Physical);
+
+ ent = ZZ_NewLink(it);
+ if (ent == NULL) {
+ err = JAR_ERR_MEMORY;
+ goto loser;
+ }
+
+ ZZ_AppendLink(jar->phy, ent);
+ pos = phy->offset + phy->length;
+ } else if (sigVal == CSIG) {
+ unsigned int attr = 0;
+ if (JAR_FREAD(fp, Central, sizeof *Central) != sizeof *Central) {
+ /* apparently truncated archive */
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
#if defined(XP_UNIX) || defined(XP_BEOS)
- /* with unix we need to locate any bits from
- the protection mask in the external attributes. */
- attr = Central->external_attributes [2]; /* magic */
- if (attr) {
- /* we have to read the filename, again */
- filename_len = x86ShortToUint32(Central->filename_len);
- if (filename_len >= JAR_SIZE) {
- /* corrupt in central directory */
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
-
- if (JAR_FREAD(fp, filename, filename_len) != filename_len) {
- /* truncated in central directory */
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
- filename [filename_len] = 0;
-
- /* look up this name again */
- phy = jar_get_physical (jar, filename);
- if (phy) {
- /* always allow access by self */
- phy->mode = 0400 | attr;
- }
- }
+ /* with unix we need to locate any bits from
+ the protection mask in the external attributes. */
+ attr = Central->external_attributes[2]; /* magic */
+ if (attr) {
+ /* we have to read the filename, again */
+ filename_len = x86ShortToUint32(Central->filename_len);
+ if (filename_len >= JAR_SIZE) {
+ /* corrupt in central directory */
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
+
+ if (JAR_FREAD(fp, filename, filename_len) != filename_len) {
+ /* truncated in central directory */
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
+ filename[filename_len] = 0;
+
+ /* look up this name again */
+ phy = jar_get_physical(jar, filename);
+ if (phy) {
+ /* always allow access by self */
+ phy->mode = 0400 | attr;
+ }
+ }
#endif
- pos += sizeof(struct ZipCentral)
- + x86ShortToUint32(Central->filename_len)
- + x86ShortToUint32(Central->commentfield_len)
- + x86ShortToUint32(Central->extrafield_len);
- } else if (sigVal == ESIG) {
- if (JAR_FREAD(fp, End, sizeof *End) != sizeof *End) {
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
- break;
- } else {
- /* garbage in archive */
- err = JAR_ERR_CORRUPT;
- goto loser;
- }
+ pos += sizeof(struct ZipCentral) +
+ x86ShortToUint32(Central->filename_len) +
+ x86ShortToUint32(Central->commentfield_len) +
+ x86ShortToUint32(Central->extrafield_len);
+ } else if (sigVal == ESIG) {
+ if (JAR_FREAD(fp, End, sizeof *End) != sizeof *End) {
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
+ break;
+ } else {
+ /* garbage in archive */
+ err = JAR_ERR_CORRUPT;
+ goto loser;
+ }
}
loser:
- if (Local)
- PORT_Free(Local);
- if (Central)
- PORT_Free(Central);
- if (End)
- PORT_Free(End);
+ if (Local)
+ PORT_Free(Local);
+ if (Central)
+ PORT_Free(Central);
+ if (End)
+ PORT_Free(End);
return err;
}
@@ -820,7 +816,7 @@ loser:
* .tar file into the JAR linked list.
*
*/
-static int
+static int
jar_listtar(JAR *jar, JAR_FILE fp)
{
char *s;
@@ -830,37 +826,37 @@ jar_listtar(JAR *jar, JAR_FILE fp)
union TarEntry tarball;
while (1) {
- JAR_FSEEK (fp, pos, (PRSeekWhence)0);
+ JAR_FSEEK(fp, pos, (PRSeekWhence)0);
- if (JAR_FREAD (fp, &tarball, sizeof tarball) < sizeof tarball)
- break;
+ if (JAR_FREAD(fp, &tarball, sizeof tarball) < sizeof tarball)
+ break;
- if (!*tarball.val.filename)
- break;
+ if (!*tarball.val.filename)
+ break;
- sz = octalToLong (tarball.val.size);
+ sz = octalToLong(tarball.val.size);
- /* Tag the end of filename */
- s = tarball.val.filename;
- while (*s && *s != ' ')
- s++;
- *s = 0;
+ /* Tag the end of filename */
+ s = tarball.val.filename;
+ while (*s && *s != ' ')
+ s++;
+ *s = 0;
- /* Add to our linked list */
- phy = PORT_ZNew(JAR_Physical);
- if (phy == NULL)
- return JAR_ERR_MEMORY;
+ /* Add to our linked list */
+ phy = PORT_ZNew(JAR_Physical);
+ if (phy == NULL)
+ return JAR_ERR_MEMORY;
- phy->compression = 0;
- phy->offset = pos + sizeof tarball;
- phy->length = sz;
+ phy->compression = 0;
+ phy->offset = pos + sizeof tarball;
+ phy->length = sz;
- ADDITEM(jar->phy, jarTypePhy, tarball.val.filename, phy,
- sizeof *phy);
+ ADDITEM(jar->phy, jarTypePhy, tarball.val.filename, phy,
+ sizeof *phy);
- /* Advance to next file entry */
- sz = PR_ROUNDUP(sz,sizeof tarball);
- pos += sz + sizeof tarball;
+ /* Advance to next file entry */
+ sz = PR_ROUNDUP(sz, sizeof tarball);
+ pos += sz + sizeof tarball;
}
return 0;
@@ -873,13 +869,13 @@ jar_listtar(JAR *jar, JAR_FILE fp)
* it will be needed.
*
*/
-static int
+static int
dosdate(char *date, const char *s)
{
PRUint32 num = x86ShortToUint32(s);
- PR_snprintf(date, 9, "%02d-%02d-%02d", ((num >> 5) & 0x0F), (num & 0x1F),
- ((num >> 9) + 80));
+ PR_snprintf(date, 9, "%02d-%02d-%02d", ((num >> 5) & 0x0F), (num & 0x1F),
+ ((num >> 9) + 80));
return 0;
}
@@ -890,13 +886,13 @@ dosdate(char *date, const char *s)
* it will be needed.
*
*/
-static int
-dostime (char *time, const char *s)
+static int
+dostime(char *time, const char *s)
{
PRUint32 num = x86ShortToUint32(s);
- PR_snprintf (time, 6, "%02d:%02d", ((num >> 11) & 0x1F),
- ((num >> 5) & 0x3F));
+ PR_snprintf(time, 6, "%02d:%02d", ((num >> 11) & 0x1F),
+ ((num >> 5) & 0x3F));
return 0;
}
@@ -905,7 +901,7 @@ dostime (char *time, const char *s)
* Simulates an x86 (little endian, unaligned) ushort fetch from any address.
*/
static PRUint32
-x86ShortToUint32(const void * v)
+x86ShortToUint32(const void *v)
{
const unsigned char *ii = (const unsigned char *)v;
PRUint32 ret = (PRUint32)(ii[0]) | ((PRUint32)(ii[1]) << 8);
@@ -921,10 +917,10 @@ x86LongToUint32(const void *v)
const unsigned char *ll = (const unsigned char *)v;
PRUint32 ret;
- ret = ((((PRUint32)(ll[0])) << 0) |
- (((PRUint32)(ll[1])) << 8) |
- (((PRUint32)(ll[2])) << 16) |
- (((PRUint32)(ll[3])) << 24));
+ ret = ((((PRUint32)(ll[0])) << 0) |
+ (((PRUint32)(ll[1])) << 8) |
+ (((PRUint32)(ll[2])) << 16) |
+ (((PRUint32)(ll[3])) << 24));
return ret;
}
#endif
@@ -934,16 +930,16 @@ x86LongToUint32(const void *v)
* Used for integer encoding inside tar files.
*
*/
-static long
+static long
octalToLong(const char *s)
{
long num = 0L;
- while (*s == ' ')
- s++;
+ while (*s == ' ')
+ s++;
while (*s >= '0' && *s <= '7') {
- num <<= 3;
- num += *s++ - '0';
+ num <<= 3;
+ num += *s++ - '0';
}
return num;
}
@@ -956,13 +952,13 @@ octalToLong(const char *s)
* or at its filename.
*
*/
-static int
+static int
jar_guess_jar(const char *filename, JAR_FILE fp)
{
PRInt32 len = PORT_Strlen(filename);
const char *ext = filename + len - 4; /* 4 for ".tar" */
if (len >= 4 && !PL_strcasecmp(ext, ".tar"))
- return jarArchTar;
+ return jarArchTar;
return jarArchZip;
}
diff --git a/lib/jar/jarfile.h b/lib/jar/jarfile.h
index 667415d45..52d4f1fc7 100644
--- a/lib/jar/jarfile.h
+++ b/lib/jar/jarfile.h
@@ -10,49 +10,49 @@
*/
/* ZIP */
-struct ZipLocal { /* 30 bytes */
- char signature [4];
- char word [2];
- char bitflag [2];
- char method [2];
- char time [2];
- char date [2];
- char crc32 [4];
- char size [4];
- char orglen [4];
- char filename_len [2];
- char extrafield_len [2];
+struct ZipLocal { /* 30 bytes */
+ char signature[4];
+ char word[2];
+ char bitflag[2];
+ char method[2];
+ char time[2];
+ char date[2];
+ char crc32[4];
+ char size[4];
+ char orglen[4];
+ char filename_len[2];
+ char extrafield_len[2];
};
-struct ZipCentral { /* 46 bytes */
- char signature [4];
- char version_made_by [2];
- char version [2];
- char bitflag [2];
- char method [2];
- char time [2];
- char date [2];
- char crc32 [4];
- char size [4];
- char orglen [4];
- char filename_len [2];
- char extrafield_len [2];
- char commentfield_len [2];
- char diskstart_number [2];
- char internal_attributes [2];
- char external_attributes [4];
- char localhdr_offset [4];
+struct ZipCentral { /* 46 bytes */
+ char signature[4];
+ char version_made_by[2];
+ char version[2];
+ char bitflag[2];
+ char method[2];
+ char time[2];
+ char date[2];
+ char crc32[4];
+ char size[4];
+ char orglen[4];
+ char filename_len[2];
+ char extrafield_len[2];
+ char commentfield_len[2];
+ char diskstart_number[2];
+ char internal_attributes[2];
+ char external_attributes[4];
+ char localhdr_offset[4];
};
-struct ZipEnd { /* 22 bytes */
- char signature [4];
- char disk_nr [2];
- char start_central_dir [2];
- char total_entries_disk [2];
- char total_entries_archive [2];
- char central_dir_size [4];
- char offset_central_dir [4];
- char commentfield_len [2];
+struct ZipEnd { /* 22 bytes */
+ char signature[4];
+ char disk_nr[2];
+ char start_central_dir[2];
+ char total_entries_disk[2];
+ char total_entries_archive[2];
+ char central_dir_size[4];
+ char offset_central_dir[4];
+ char commentfield_len[2];
};
#define LSIG 0x04034B50l
@@ -60,17 +60,17 @@ struct ZipEnd { /* 22 bytes */
#define ESIG 0x06054B50l
/* TAR */
-union TarEntry { /* 512 bytes */
- struct header { /* 257 bytes */
- char filename [100];
- char mode [8];
- char uid [8];
- char gid [8];
- char size [12];
- char time [12];
- char checksum [8];
- char linkflag;
- char linkname [100];
+union TarEntry { /* 512 bytes */
+ struct header { /* 257 bytes */
+ char filename[100];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char time[12];
+ char checksum[8];
+ char linkflag;
+ char linkname[100];
} val;
- char buffer [512];
+ char buffer[512];
};
diff --git a/lib/jar/jarint.c b/lib/jar/jarint.c
index 2fa220b2a..b0ef7fb21 100644
--- a/lib/jar/jarint.c
+++ b/lib/jar/jarint.c
@@ -14,34 +14,34 @@
* Translate JAR_FOPEN arguments to PR_Open arguments
*/
PRFileDesc*
-JAR_FOPEN_to_PR_Open(const char* name, const char *mode)
+JAR_FOPEN_to_PR_Open(const char* name, const char* mode)
{
- PRIntn prflags=0, prmode=0;
+ PRIntn prflags = 0, prmode = 0;
/* Get read/write flags */
if (strchr(mode, 'r') && !strchr(mode, '+')) {
- prflags |= PR_RDONLY;
- } else if( (strchr(mode, 'w') || strchr(mode, 'a')) &&
- !strchr(mode,'+') ) {
- prflags |= PR_WRONLY;
+ prflags |= PR_RDONLY;
+ } else if ((strchr(mode, 'w') || strchr(mode, 'a')) &&
+ !strchr(mode, '+')) {
+ prflags |= PR_WRONLY;
} else {
- prflags |= PR_RDWR;
+ prflags |= PR_RDWR;
}
/* Create a new file? */
if (strchr(mode, 'w') || strchr(mode, 'a')) {
- prflags |= PR_CREATE_FILE;
+ prflags |= PR_CREATE_FILE;
}
/* Append? */
if (strchr(mode, 'a')) {
- prflags |= PR_APPEND;
+ prflags |= PR_APPEND;
}
/* Truncate? */
if (strchr(mode, 'w')) {
- prflags |= PR_TRUNCATE;
+ prflags |= PR_TRUNCATE;
}
/* We can't do umask because it isn't XP. Choose some default
diff --git a/lib/jar/jarint.h b/lib/jar/jarint.h
index 214b8a1d1..21aecef89 100644
--- a/lib/jar/jarint.h
+++ b/lib/jar/jarint.h
@@ -8,33 +8,33 @@
#include "key.h"
#include "base64.h"
-extern CERTCertDBHandle *JAR_open_database (void);
+extern CERTCertDBHandle *JAR_open_database(void);
-extern int JAR_close_database (CERTCertDBHandle *certdb);
+extern int JAR_close_database(CERTCertDBHandle *certdb);
-extern int jar_close_key_database (void *keydb);
+extern int jar_close_key_database(void *keydb);
-extern void *jar_open_key_database (void);
+extern void *jar_open_key_database(void);
-extern JAR_Signer *JAR_new_signer (void);
+extern JAR_Signer *JAR_new_signer(void);
-extern void JAR_destroy_signer (JAR_Signer *signer);
+extern void JAR_destroy_signer(JAR_Signer *signer);
-extern JAR_Signer *jar_get_signer (JAR *jar, char *basename);
+extern JAR_Signer *jar_get_signer(JAR *jar, char *basename);
-extern int
+extern int
jar_append(ZZList *list, int type, char *pathname, void *data, size_t size);
/* Translate fopen mode arg to PR_Open flags and mode */
-PRFileDesc*
+PRFileDesc *
JAR_FOPEN_to_PR_Open(const char *name, const char *mode);
-#define ADDITEM(list,type,pathname,data,size) \
-{ \
- int err = jar_append (list, type, pathname, data, size); \
- if (err < 0) \
- return err; \
-}
+#define ADDITEM(list, type, pathname, data, size) \
+ { \
+ int err = jar_append(list, type, pathname, data, size); \
+ if (err < 0) \
+ return err; \
+ }
/* Here is some ugliness in the event it is necessary to link
with NSPR 1.0 libraries, which do not include an FSEEK. It is
@@ -42,14 +42,13 @@ JAR_FOPEN_to_PR_Open(const char *name, const char *mode);
/* nspr 2.0 suite */
#define JAR_FILE PRFileDesc *
-#define JAR_FOPEN(fn,mode) JAR_FOPEN_to_PR_Open(fn,mode)
+#define JAR_FOPEN(fn, mode) JAR_FOPEN_to_PR_Open(fn, mode)
#define JAR_FCLOSE PR_Close
#define JAR_FSEEK PR_Seek
#define JAR_FREAD PR_Read
#define JAR_FWRITE PR_Write
-int
+int
jar_create_pk7(CERTCertDBHandle *certdb, void *keydb,
CERTCertificate *cert, char *password, JAR_FILE infp,
JAR_FILE outfp);
-
diff --git a/lib/jar/jarnav.c b/lib/jar/jarnav.c
index 6ae763c32..8b72a52d8 100644
--- a/lib/jar/jarnav.c
+++ b/lib/jar/jarnav.c
@@ -16,10 +16,10 @@
extern MWContext *FE_GetInitContext(void);
/* To return an MWContext for Java */
-static MWContext *(*jar_fn_FindSomeContext) (void) = NULL;
+static MWContext *(*jar_fn_FindSomeContext)(void) = NULL;
/* To fabricate an MWContext for FE_GetPassword */
-static MWContext *(*jar_fn_GetInitContext) (void) = NULL;
+static MWContext *(*jar_fn_GetInitContext)(void) = NULL;
/*
* J A R _ i n i t
@@ -28,9 +28,10 @@ static MWContext *(*jar_fn_GetInitContext) (void) = NULL;
*
*/
-void JAR_init (void)
+void
+JAR_init(void)
{
- JAR_init_callbacks (XP_GetString, NULL, NULL);
+ JAR_init_callbacks(XP_GetString, NULL, NULL);
}
/*
@@ -40,23 +41,23 @@ void JAR_init (void)
* it may be needed to prompt the user for a password.
*
*/
-int
+int
JAR_set_context(JAR *jar, MWContext *mw)
{
if (mw) {
- jar->mw = mw;
+ jar->mw = mw;
} else {
- /* jar->mw = XP_FindSomeContext(); */
- jar->mw = NULL;
- /*
- * We can't find a context because we're in startup state and none
- * exist yet. go get an FE_InitContext that only works at
- * initialization time.
- */
- /* Turn on the mac when we get the FE_ function */
- if (jar->mw == NULL) {
- jar->mw = jar_fn_GetInitContext();
- }
+ /* jar->mw = XP_FindSomeContext(); */
+ jar->mw = NULL;
+ /*
+ * We can't find a context because we're in startup state and none
+ * exist yet. go get an FE_InitContext that only works at
+ * initialization time.
+ */
+ /* Turn on the mac when we get the FE_ function */
+ if (jar->mw == NULL) {
+ jar->mw = jar_fn_GetInitContext();
+ }
}
return 0;
}
diff --git a/lib/jar/jarsign.c b/lib/jar/jarsign.c
index d05bd2b4b..601a7fd04 100644
--- a/lib/jar/jarsign.c
+++ b/lib/jar/jarsign.c
@@ -8,7 +8,6 @@
* Routines used in signing archives.
*/
-
#include "jar.h"
#include "jarint.h"
#include "secpkcs7.h"
@@ -16,7 +15,7 @@
#include "sechash.h"
/* from libevent.h */
-typedef void (*ETVoidPtrFunc) (void * data);
+typedef void (*ETVoidPtrFunc)(void *data);
/* key database wrapper */
/* static SECKEYKeyDBHandle *jar_open_key_database (void); */
@@ -35,52 +34,51 @@ typedef void (*ETVoidPtrFunc) (void * data);
* This version supports huge pointers for WIN16.
*
*/
-JAR_Digest * PR_CALLBACK
+JAR_Digest *PR_CALLBACK
JAR_calculate_digest(void *data, long length)
{
- PK11Context *md5 = 0;
+ PK11Context *md5 = 0;
PK11Context *sha1 = 0;
- JAR_Digest *dig = PORT_ZNew(JAR_Digest);
+ JAR_Digest *dig = PORT_ZNew(JAR_Digest);
long chunq;
unsigned int md5_length, sha1_length;
if (dig == NULL) {
- /* out of memory allocating digest */
- return NULL;
+ /* out of memory allocating digest */
+ return NULL;
}
md5 = PK11_CreateDigestContext(SEC_OID_MD5);
if (md5 == NULL) {
- PORT_ZFree(dig, sizeof(JAR_Digest));
- return NULL;
+ PORT_ZFree(dig, sizeof(JAR_Digest));
+ return NULL;
}
sha1 = PK11_CreateDigestContext(SEC_OID_SHA1);
if (sha1 == NULL) {
- PK11_DestroyContext(md5, PR_TRUE);
- /* added due to bug Bug 1250214 - prevent the 2nd memory leak */
- PORT_ZFree(dig, sizeof(JAR_Digest));
- return NULL;
+ PK11_DestroyContext(md5, PR_TRUE);
+ /* added due to bug Bug 1250214 - prevent the 2nd memory leak */
+ PORT_ZFree(dig, sizeof(JAR_Digest));
+ return NULL;
}
if (length >= 0) {
- PK11_DigestBegin (md5);
- PK11_DigestBegin (sha1);
+ PK11_DigestBegin(md5);
+ PK11_DigestBegin(sha1);
- do {
- chunq = length;
+ do {
+ chunq = length;
- PK11_DigestOp(md5, (unsigned char*)data, chunq);
- PK11_DigestOp(sha1, (unsigned char*)data, chunq);
- length -= chunq;
- data = ((char *) data + chunq);
- }
- while (length > 0);
+ PK11_DigestOp(md5, (unsigned char *)data, chunq);
+ PK11_DigestOp(sha1, (unsigned char *)data, chunq);
+ length -= chunq;
+ data = ((char *)data + chunq);
+ } while (length > 0);
- PK11_DigestFinal (md5, dig->md5, &md5_length, MD5_LENGTH);
- PK11_DigestFinal (sha1, dig->sha1, &sha1_length, SHA1_LENGTH);
+ PK11_DigestFinal(md5, dig->md5, &md5_length, MD5_LENGTH);
+ PK11_DigestFinal(sha1, dig->sha1, &sha1_length, SHA1_LENGTH);
- PK11_DestroyContext (md5, PR_TRUE);
- PK11_DestroyContext (sha1, PR_TRUE);
+ PK11_DestroyContext(md5, PR_TRUE);
+ PK11_DestroyContext(sha1, PR_TRUE);
}
return dig;
}
@@ -92,62 +90,62 @@ JAR_calculate_digest(void *data, long length)
* present on disk, and returns these in JAR_Digest struct.
*
*/
-int
-JAR_digest_file (char *filename, JAR_Digest *dig)
+int
+JAR_digest_file(char *filename, JAR_Digest *dig)
{
JAR_FILE fp;
PK11Context *md5 = 0;
PK11Context *sha1 = 0;
- unsigned char *buf = (unsigned char *) PORT_ZAlloc (FILECHUNQ);
+ unsigned char *buf = (unsigned char *)PORT_ZAlloc(FILECHUNQ);
int num;
unsigned int md5_length, sha1_length;
if (buf == NULL) {
- /* out of memory */
- return JAR_ERR_MEMORY;
+ /* out of memory */
+ return JAR_ERR_MEMORY;
}
- if ((fp = JAR_FOPEN (filename, "rb")) == 0) {
- /* perror (filename); FIX XXX XXX XXX XXX XXX XXX */
- PORT_Free (buf);
- return JAR_ERR_FNF;
+ if ((fp = JAR_FOPEN(filename, "rb")) == 0) {
+ /* perror (filename); FIX XXX XXX XXX XXX XXX XXX */
+ PORT_Free(buf);
+ return JAR_ERR_FNF;
}
- md5 = PK11_CreateDigestContext (SEC_OID_MD5);
- sha1 = PK11_CreateDigestContext (SEC_OID_SHA1);
+ md5 = PK11_CreateDigestContext(SEC_OID_MD5);
+ sha1 = PK11_CreateDigestContext(SEC_OID_SHA1);
if (md5 == NULL || sha1 == NULL) {
- if (md5) {
- PK11_DestroyContext(md5, PR_TRUE);
- }
- if (sha1) {
- PK11_DestroyContext(sha1, PR_TRUE);
- }
- /* can't generate digest contexts */
- PORT_Free (buf);
- JAR_FCLOSE (fp);
- return JAR_ERR_GENERAL;
+ if (md5) {
+ PK11_DestroyContext(md5, PR_TRUE);
+ }
+ if (sha1) {
+ PK11_DestroyContext(sha1, PR_TRUE);
+ }
+ /* can't generate digest contexts */
+ PORT_Free(buf);
+ JAR_FCLOSE(fp);
+ return JAR_ERR_GENERAL;
}
- PK11_DigestBegin (md5);
- PK11_DigestBegin (sha1);
+ PK11_DigestBegin(md5);
+ PK11_DigestBegin(sha1);
while (1) {
- if ((num = JAR_FREAD (fp, buf, FILECHUNQ)) == 0)
- break;
+ if ((num = JAR_FREAD(fp, buf, FILECHUNQ)) == 0)
+ break;
- PK11_DigestOp (md5, buf, num);
- PK11_DigestOp (sha1, buf, num);
+ PK11_DigestOp(md5, buf, num);
+ PK11_DigestOp(sha1, buf, num);
}
- PK11_DigestFinal (md5, dig->md5, &md5_length, MD5_LENGTH);
- PK11_DigestFinal (sha1, dig->sha1, &sha1_length, SHA1_LENGTH);
+ PK11_DigestFinal(md5, dig->md5, &md5_length, MD5_LENGTH);
+ PK11_DigestFinal(sha1, dig->sha1, &sha1_length, SHA1_LENGTH);
- PK11_DestroyContext (md5, PR_TRUE);
- PK11_DestroyContext (sha1, PR_TRUE);
+ PK11_DestroyContext(md5, PR_TRUE);
+ PK11_DestroyContext(sha1, PR_TRUE);
- PORT_Free (buf);
- JAR_FCLOSE (fp);
+ PORT_Free(buf);
+ JAR_FCLOSE(fp);
return 0;
}
@@ -157,32 +155,32 @@ JAR_digest_file (char *filename, JAR_Digest *dig)
*
*/
-void*
+void *
jar_open_key_database(void)
{
return NULL;
}
-int
+int
jar_close_key_database(void *keydb)
{
/* We never do close it */
return 0;
}
-
/*
* j a r _ c r e a t e _ p k 7
*
*/
-static void jar_pk7_out (void *arg, const char *buf, unsigned long len)
+static void
+jar_pk7_out(void *arg, const char *buf, unsigned long len)
{
- JAR_FWRITE ((JAR_FILE) arg, buf, len);
+ JAR_FWRITE((JAR_FILE)arg, buf, len);
}
-int
-jar_create_pk7(CERTCertDBHandle *certdb, void *keydb, CERTCertificate *cert,
+int
+jar_create_pk7(CERTCertDBHandle *certdb, void *keydb, CERTCertificate *cert,
char *password, JAR_FILE infp, JAR_FILE outfp)
{
SEC_PKCS7ContentInfo *cinfo;
@@ -197,42 +195,42 @@ jar_create_pk7(CERTCertDBHandle *certdb, void *keydb, CERTCertificate *cert,
unsigned char buffer[4096];
if (outfp == NULL || infp == NULL || cert == NULL)
- return JAR_ERR_GENERAL;
+ return JAR_ERR_GENERAL;
/* we sign with SHA */
hashObj = HASH_GetHashObject(HASH_AlgSHA1);
- hashcx = (* hashObj->create)();
+ hashcx = (*hashObj->create)();
if (hashcx == NULL)
- return JAR_ERR_GENERAL;
+ return JAR_ERR_GENERAL;
- (* hashObj->begin)(hashcx);
+ (*hashObj->begin)(hashcx);
while (1) {
- int nb = JAR_FREAD(infp, buffer, sizeof buffer);
- if (nb == 0) { /* eof */
- break;
- }
- (* hashObj->update) (hashcx, buffer, nb);
+ int nb = JAR_FREAD(infp, buffer, sizeof buffer);
+ if (nb == 0) { /* eof */
+ break;
+ }
+ (*hashObj->update)(hashcx, buffer, nb);
}
- (* hashObj->end)(hashcx, digestdata, &len, 32);
- (* hashObj->destroy)(hashcx, PR_TRUE);
+ (*hashObj->end)(hashcx, digestdata, &len, 32);
+ (*hashObj->destroy)(hashcx, PR_TRUE);
digest.data = digestdata;
digest.len = len;
/* signtool must use any old context it can find since it's
- calling from inside javaland. */
- PORT_SetError (0);
+ calling from inside javaland. */
+ PORT_SetError(0);
cinfo = SEC_PKCS7CreateSignedData(cert, certUsageObjectSigner, NULL,
SEC_OID_SHA1, &digest, NULL, mw);
if (cinfo == NULL)
- return JAR_ERR_PK7;
+ return JAR_ERR_PK7;
rv = SEC_PKCS7IncludeCertChain(cinfo, NULL);
if (rv != SECSuccess) {
- status = PORT_GetError();
- SEC_PKCS7DestroyContentInfo(cinfo);
- return status;
+ status = PORT_GetError();
+ SEC_PKCS7DestroyContentInfo(cinfo);
+ return status;
}
/* Having this here forces signtool to always include signing time. */
@@ -243,10 +241,10 @@ jar_create_pk7(CERTCertDBHandle *certdb, void *keydb, CERTCertificate *cert,
/* if calling from mozilla thread*/
rv = SEC_PKCS7Encode(cinfo, jar_pk7_out, outfp, NULL, NULL, mw);
if (rv != SECSuccess)
- status = PORT_GetError();
- SEC_PKCS7DestroyContentInfo (cinfo);
+ status = PORT_GetError();
+ SEC_PKCS7DestroyContentInfo(cinfo);
if (rv != SECSuccess) {
- return ((status < 0) ? status : JAR_ERR_GENERAL);
+ return ((status < 0) ? status : JAR_ERR_GENERAL);
}
return 0;
}
diff --git a/lib/jar/jarver.c b/lib/jar/jarver.c
index fa3c8a0db..d9eee448d 100644
--- a/lib/jar/jarver.c
+++ b/lib/jar/jarver.c
@@ -37,7 +37,7 @@ static JAR_Digest *jar_get_mf_digest(JAR *jar, char *path);
static int
jar_parse_digital_signature(char *raw_manifest, JAR_Signer *signer,
- long length, JAR *jar);
+ long length, JAR *jar);
static int
jar_add_cert(JAR *jar, JAR_Signer *signer, int type, CERTCertificate *cert);
@@ -53,20 +53,20 @@ static int jar_insanity_check(char *data, long length);
int
jar_parse_mf(JAR *jar, char *raw_manifest, long length,
- const char *path, const char *url);
+ const char *path, const char *url);
int
jar_parse_sf(JAR *jar, char *raw_manifest, long length,
- const char *path, const char *url);
+ const char *path, const char *url);
int
jar_parse_sig(JAR *jar, const char *path, char *raw_manifest,
- long length);
+ long length);
int
jar_parse_any(JAR *jar, int type, JAR_Signer *signer,
- char *raw_manifest, long length, const char *path,
- const char *url);
+ char *raw_manifest, long length, const char *path,
+ const char *url);
static int
jar_internal_digest(JAR *jar, const char *path, char *x_name, JAR_Digest *dig);
@@ -83,45 +83,43 @@ jar_internal_digest(JAR *jar, const char *path, char *x_name, JAR_Digest *dig);
*/
int
JAR_parse_manifest(JAR *jar, char *raw_manifest, long length,
- const char *path, const char *url)
+ const char *path, const char *url)
{
int filename_free = 0;
/* fill in the path, if supplied. This is the location
- of the jar file on disk, if known */
+ of the jar file on disk, if known */
if (jar->filename == NULL && path) {
- jar->filename = PORT_Strdup(path);
- if (jar->filename == NULL)
- return JAR_ERR_MEMORY;
- filename_free = 1;
+ jar->filename = PORT_Strdup(path);
+ if (jar->filename == NULL)
+ return JAR_ERR_MEMORY;
+ filename_free = 1;
}
/* fill in the URL, if supplied. This is the place
- from which the jar file was retrieved. */
+ from which the jar file was retrieved. */
if (jar->url == NULL && url) {
- jar->url = PORT_Strdup(url);
- if (jar->url == NULL) {
- if (filename_free) {
- PORT_Free(jar->filename);
- }
- return JAR_ERR_MEMORY;
- }
+ jar->url = PORT_Strdup(url);
+ if (jar->url == NULL) {
+ if (filename_free) {
+ PORT_Free(jar->filename);
+ }
+ return JAR_ERR_MEMORY;
+ }
}
/* Determine what kind of file this is from the META-INF
- directory. It could be MF, SF, or a binary RSA/DSA file */
+ directory. It could be MF, SF, or a binary RSA/DSA file */
- if (!PORT_Strncasecmp (raw_manifest, "Manifest-Version:", 17)) {
- return jar_parse_mf(jar, raw_manifest, length, path, url);
- }
- else if (!PORT_Strncasecmp (raw_manifest, "Signature-Version:", 18))
- {
- return jar_parse_sf(jar, raw_manifest, length, path, url);
+ if (!PORT_Strncasecmp(raw_manifest, "Manifest-Version:", 17)) {
+ return jar_parse_mf(jar, raw_manifest, length, path, url);
+ } else if (!PORT_Strncasecmp(raw_manifest, "Signature-Version:", 18)) {
+ return jar_parse_sf(jar, raw_manifest, length, path, url);
} else {
- /* This is probably a binary signature */
- return jar_parse_sig(jar, path, raw_manifest, length);
+ /* This is probably a binary signature */
+ return jar_parse_sig(jar, path, raw_manifest, length);
}
}
@@ -134,47 +132,46 @@ JAR_parse_manifest(JAR *jar, char *raw_manifest, long length,
*/
int
jar_parse_sig(JAR *jar, const char *path, char *raw_manifest,
- long length)
+ long length)
{
JAR_Signer *signer;
int status = JAR_ERR_ORDER;
if (length <= 128) {
- /* signature is way too small */
- return JAR_ERR_SIG;
+ /* signature is way too small */
+ return JAR_ERR_SIG;
}
/* make sure that MF and SF have already been processed */
if (jar->globalmeta == NULL)
- return JAR_ERR_ORDER;
+ return JAR_ERR_ORDER;
/* Determine whether or not this RSA file has
- has an associated SF file */
+ has an associated SF file */
if (path) {
- char *owner;
- owner = jar_basename(path);
+ char *owner;
+ owner = jar_basename(path);
- if (owner == NULL)
- return JAR_ERR_MEMORY;
+ if (owner == NULL)
+ return JAR_ERR_MEMORY;
- signer = jar_get_signer(jar, owner);
- PORT_Free(owner);
+ signer = jar_get_signer(jar, owner);
+ PORT_Free(owner);
} else
- signer = jar_get_signer(jar, "*");
+ signer = jar_get_signer(jar, "*");
if (signer == NULL)
- return JAR_ERR_ORDER;
-
+ return JAR_ERR_ORDER;
/* Do not pass a huge pointer to this function,
- since the underlying security code is unaware. We will
- never pass >64k through here. */
+ since the underlying security code is unaware. We will
+ never pass >64k through here. */
if (length > 64000) {
- /* this digital signature is way too big */
- return JAR_ERR_SIG;
+ /* this digital signature is way too big */
+ return JAR_ERR_SIG;
}
/* don't expense unneeded calloc overhead on non-win16 */
@@ -192,19 +189,19 @@ jar_parse_sig(JAR *jar, const char *path, char *raw_manifest,
*/
int
jar_parse_mf(JAR *jar, char *raw_manifest, long length,
- const char *path, const char *url)
+ const char *path, const char *url)
{
if (jar->globalmeta) {
- /* refuse a second manifest file, if passed for some reason */
- return JAR_ERR_ORDER;
+ /* refuse a second manifest file, if passed for some reason */
+ return JAR_ERR_ORDER;
}
/* remember a digest for the global section */
jar->globalmeta = jar_digest_section(raw_manifest, length);
if (jar->globalmeta == NULL)
- return JAR_ERR_MEMORY;
+ return JAR_ERR_MEMORY;
return jar_parse_any(jar, jarTypeMF, NULL, raw_manifest, length,
- path, url);
+ path, url);
}
/*
@@ -216,50 +213,50 @@ jar_parse_mf(JAR *jar, char *raw_manifest, long length,
*/
int
jar_parse_sf(JAR *jar, char *raw_manifest, long length,
- const char *path, const char *url)
+ const char *path, const char *url)
{
JAR_Signer *signer = NULL;
int status = JAR_ERR_MEMORY;
if (jar->globalmeta == NULL) {
- /* It is a requirement that the MF file be passed before the SF file */
- return JAR_ERR_ORDER;
+ /* It is a requirement that the MF file be passed before the SF file */
+ return JAR_ERR_ORDER;
}
signer = JAR_new_signer();
if (signer == NULL)
- goto loser;
+ goto loser;
if (path) {
- signer->owner = jar_basename(path);
- if (signer->owner == NULL)
- goto loser;
+ signer->owner = jar_basename(path);
+ if (signer->owner == NULL)
+ goto loser;
}
/* check for priors. When someone doctors a jar file
- to contain identical path entries, prevent the second
- one from affecting JAR functions */
+ to contain identical path entries, prevent the second
+ one from affecting JAR functions */
if (jar_get_signer(jar, signer->owner)) {
- /* someone is trying to spoof us */
- status = JAR_ERR_ORDER;
- goto loser;
+ /* someone is trying to spoof us */
+ status = JAR_ERR_ORDER;
+ goto loser;
}
/* remember its digest */
- signer->digest = JAR_calculate_digest (raw_manifest, length);
+ signer->digest = JAR_calculate_digest(raw_manifest, length);
if (signer->digest == NULL)
- goto loser;
+ goto loser;
/* Add this signer to the jar */
ADDITEM(jar->signers, jarTypeOwner, signer->owner, signer,
- sizeof (JAR_Signer));
+ sizeof(JAR_Signer));
return jar_parse_any(jar, jarTypeSF, signer, raw_manifest, length,
- path, url);
+ path, url);
loser:
if (signer)
- JAR_destroy_signer (signer);
+ JAR_destroy_signer(signer);
return status;
}
@@ -269,16 +266,16 @@ loser:
* Parse a MF or SF manifest file.
*
*/
-int
-jar_parse_any(JAR *jar, int type, JAR_Signer *signer,
- char *raw_manifest, long length, const char *path,
- const char *url)
+int
+jar_parse_any(JAR *jar, int type, JAR_Signer *signer,
+ char *raw_manifest, long length, const char *path,
+ const char *url)
{
int status;
long raw_len;
JAR_Digest *dig, *mfdig = NULL;
- char line [SZ];
- char x_name [SZ], x_md5 [SZ], x_sha [SZ];
+ char line[SZ];
+ char x_name[SZ], x_md5[SZ], x_sha[SZ];
char *x_info;
char *sf_md5 = NULL, *sf_sha1 = NULL;
@@ -286,12 +283,12 @@ jar_parse_any(JAR *jar, int type, JAR_Signer *signer,
*x_md5 = 0;
*x_sha = 0;
- PORT_Assert( length > 0 );
+ PORT_Assert(length > 0);
raw_len = length;
#ifdef DEBUG
if ((status = jar_insanity_check(raw_manifest, raw_len)) < 0)
- return status;
+ return status;
#endif
/* null terminate the first line */
@@ -300,262 +297,261 @@ jar_parse_any(JAR *jar, int type, JAR_Signer *signer,
/* skip over the preliminary section */
/* This is one section at the top of the file with global metainfo */
while (raw_len > 0) {
- JAR_Metainfo *met;
-
- raw_manifest = jar_eat_line(1, PR_TRUE, raw_manifest, &raw_len);
- if (raw_len <= 0 || !*raw_manifest)
- break;
-
- met = PORT_ZNew(JAR_Metainfo);
- if (met == NULL)
- return JAR_ERR_MEMORY;
-
- /* Parse out the header & info */
- if (PORT_Strlen (raw_manifest) >= SZ) {
- /* almost certainly nonsense */
- PORT_Free(met);
- continue;
- }
-
- PORT_Strcpy (line, raw_manifest);
- x_info = line;
-
- while (*x_info && *x_info != ' ' && *x_info != '\t' && *x_info != ':')
- x_info++;
-
- if (*x_info)
- *x_info++ = 0;
-
- while (*x_info == ' ' || *x_info == '\t')
- x_info++;
-
- /* metainfo (name, value) pair is now (line, x_info) */
- met->header = PORT_Strdup(line);
- met->info = PORT_Strdup(x_info);
-
- if (type == jarTypeMF) {
- ADDITEM (jar->metainfo, jarTypeMeta,
- /* pathname */ NULL, met, sizeof (JAR_Metainfo));
- }
-
- /* For SF files, this metadata may be the digests
- of the MF file, still in the "met" structure. */
-
- if (type == jarTypeSF) {
- if (!PORT_Strcasecmp(line, "MD5-Digest"))
- sf_md5 = (char *) met->info;
-
- if (!PORT_Strcasecmp(line, "SHA1-Digest") ||
- !PORT_Strcasecmp(line, "SHA-Digest"))
- sf_sha1 = (char *) met->info;
- }
-
- if (type != jarTypeMF) {
- PORT_Free(met->header);
- if (type != jarTypeSF) {
- PORT_Free(met->info);
- }
- PORT_Free(met);
- }
+ JAR_Metainfo *met;
+
+ raw_manifest = jar_eat_line(1, PR_TRUE, raw_manifest, &raw_len);
+ if (raw_len <= 0 || !*raw_manifest)
+ break;
+
+ met = PORT_ZNew(JAR_Metainfo);
+ if (met == NULL)
+ return JAR_ERR_MEMORY;
+
+ /* Parse out the header & info */
+ if (PORT_Strlen(raw_manifest) >= SZ) {
+ /* almost certainly nonsense */
+ PORT_Free(met);
+ continue;
+ }
+
+ PORT_Strcpy(line, raw_manifest);
+ x_info = line;
+
+ while (*x_info && *x_info != ' ' && *x_info != '\t' && *x_info != ':')
+ x_info++;
+
+ if (*x_info)
+ *x_info++ = 0;
+
+ while (*x_info == ' ' || *x_info == '\t')
+ x_info++;
+
+ /* metainfo (name, value) pair is now (line, x_info) */
+ met->header = PORT_Strdup(line);
+ met->info = PORT_Strdup(x_info);
+
+ if (type == jarTypeMF) {
+ ADDITEM(jar->metainfo, jarTypeMeta,
+ /* pathname */ NULL, met, sizeof(JAR_Metainfo));
+ }
+
+ /* For SF files, this metadata may be the digests
+ of the MF file, still in the "met" structure. */
+
+ if (type == jarTypeSF) {
+ if (!PORT_Strcasecmp(line, "MD5-Digest"))
+ sf_md5 = (char *)met->info;
+
+ if (!PORT_Strcasecmp(line, "SHA1-Digest") ||
+ !PORT_Strcasecmp(line, "SHA-Digest"))
+ sf_sha1 = (char *)met->info;
+ }
+
+ if (type != jarTypeMF) {
+ PORT_Free(met->header);
+ if (type != jarTypeSF) {
+ PORT_Free(met->info);
+ }
+ PORT_Free(met);
+ }
}
if (type == jarTypeSF && jar->globalmeta) {
- /* this is a SF file which may contain a digest of the manifest.mf's
- global metainfo. */
+ /* this is a SF file which may contain a digest of the manifest.mf's
+ global metainfo. */
- int match = 0;
- JAR_Digest *glob = jar->globalmeta;
+ int match = 0;
+ JAR_Digest *glob = jar->globalmeta;
- if (sf_md5) {
- unsigned int md5_length;
- unsigned char *md5_digest;
+ if (sf_md5) {
+ unsigned int md5_length;
+ unsigned char *md5_digest;
- md5_digest = ATOB_AsciiToData (sf_md5, &md5_length);
- PORT_Assert( md5_length == MD5_LENGTH );
+ md5_digest = ATOB_AsciiToData(sf_md5, &md5_length);
+ PORT_Assert(md5_length == MD5_LENGTH);
- if (md5_length != MD5_LENGTH)
- return JAR_ERR_CORRUPT;
+ if (md5_length != MD5_LENGTH)
+ return JAR_ERR_CORRUPT;
- match = PORT_Memcmp(md5_digest, glob->md5, MD5_LENGTH);
- }
+ match = PORT_Memcmp(md5_digest, glob->md5, MD5_LENGTH);
+ }
- if (sf_sha1 && match == 0) {
- unsigned int sha1_length;
- unsigned char *sha1_digest;
+ if (sf_sha1 && match == 0) {
+ unsigned int sha1_length;
+ unsigned char *sha1_digest;
- sha1_digest = ATOB_AsciiToData (sf_sha1, &sha1_length);
- PORT_Assert( sha1_length == SHA1_LENGTH );
+ sha1_digest = ATOB_AsciiToData(sf_sha1, &sha1_length);
+ PORT_Assert(sha1_length == SHA1_LENGTH);
- if (sha1_length != SHA1_LENGTH)
- return JAR_ERR_CORRUPT;
+ if (sha1_length != SHA1_LENGTH)
+ return JAR_ERR_CORRUPT;
- match = PORT_Memcmp(sha1_digest, glob->sha1, SHA1_LENGTH);
- }
+ match = PORT_Memcmp(sha1_digest, glob->sha1, SHA1_LENGTH);
+ }
- if (match != 0) {
- /* global digest doesn't match, SF file therefore invalid */
- jar->valid = JAR_ERR_METADATA;
- return JAR_ERR_METADATA;
- }
+ if (match != 0) {
+ /* global digest doesn't match, SF file therefore invalid */
+ jar->valid = JAR_ERR_METADATA;
+ return JAR_ERR_METADATA;
+ }
}
/* done with top section of global data */
while (raw_len > 0) {
- *x_md5 = 0;
- *x_sha = 0;
- *x_name = 0;
-
- /* If this is a manifest file, attempt to get a digest of the following
- section, without damaging it. This digest will be saved later. */
-
- if (type == jarTypeMF) {
- char *sec;
- long sec_len = raw_len;
-
- if (!*raw_manifest || *raw_manifest == '\n') {
- /* skip the blank line */
- sec = jar_eat_line(1, PR_FALSE, raw_manifest, &sec_len);
- } else
- sec = raw_manifest;
-
- if (sec_len > 0 && !PORT_Strncasecmp(sec, "Name:", 5)) {
- if (type == jarTypeMF)
- mfdig = jar_digest_section(sec, sec_len);
- else
- mfdig = NULL;
- }
- }
-
-
- while (raw_len > 0) {
- raw_manifest = jar_eat_line(1, PR_TRUE, raw_manifest, &raw_len);
- if (raw_len <= 0 || !*raw_manifest)
- break; /* blank line, done with this entry */
-
- if (PORT_Strlen(raw_manifest) >= SZ) {
- /* almost certainly nonsense */
- continue;
- }
-
- /* Parse out the name/value pair */
- PORT_Strcpy(line, raw_manifest);
- x_info = line;
-
- while (*x_info && *x_info != ' ' && *x_info != '\t' &&
- *x_info != ':')
- x_info++;
-
- if (*x_info)
- *x_info++ = 0;
-
- while (*x_info == ' ' || *x_info == '\t')
- x_info++;
-
- if (!PORT_Strcasecmp(line, "Name"))
- PORT_Strcpy(x_name, x_info);
- else if (!PORT_Strcasecmp(line, "MD5-Digest"))
- PORT_Strcpy(x_md5, x_info);
- else if (!PORT_Strcasecmp(line, "SHA1-Digest")
- || !PORT_Strcasecmp(line, "SHA-Digest"))
- PORT_Strcpy(x_sha, x_info);
-
- /* Algorithm list is meta info we don't care about; keeping it out
- of metadata saves significant space for large jar files */
- else if (!PORT_Strcasecmp(line, "Digest-Algorithms")
- || !PORT_Strcasecmp(line, "Hash-Algorithms"))
- continue;
-
- /* Meta info is only collected for the manifest.mf file,
- since the JAR_get_metainfo call does not support identity */
- else if (type == jarTypeMF) {
- JAR_Metainfo *met;
-
- /* this is meta-data */
- met = PORT_ZNew(JAR_Metainfo);
- if (met == NULL)
- return JAR_ERR_MEMORY;
-
- /* metainfo (name, value) pair is now (line, x_info) */
- if ((met->header = PORT_Strdup(line)) == NULL) {
- PORT_Free(met);
- return JAR_ERR_MEMORY;
- }
-
- if ((met->info = PORT_Strdup(x_info)) == NULL) {
- PORT_Free(met->header);
- PORT_Free(met);
- return JAR_ERR_MEMORY;
- }
-
- ADDITEM (jar->metainfo, jarTypeMeta,
- x_name, met, sizeof (JAR_Metainfo));
- }
- }
-
- if (!*x_name) {
- /* Whatever that was, it wasn't an entry, because we didn't get a
- name. We don't really have anything, so don't record this. */
- continue;
- }
-
- dig = PORT_ZNew(JAR_Digest);
- if (dig == NULL)
- return JAR_ERR_MEMORY;
-
- if (*x_md5) {
- unsigned int binary_length;
- unsigned char *binary_digest;
-
- binary_digest = ATOB_AsciiToData (x_md5, &binary_length);
- PORT_Assert( binary_length == MD5_LENGTH );
- if (binary_length != MD5_LENGTH) {
- PORT_Free(dig);
- return JAR_ERR_CORRUPT;
- }
- memcpy (dig->md5, binary_digest, MD5_LENGTH);
- dig->md5_status = jarHashPresent;
- }
-
- if (*x_sha ) {
- unsigned int binary_length;
- unsigned char *binary_digest;
-
- binary_digest = ATOB_AsciiToData (x_sha, &binary_length);
- PORT_Assert( binary_length == SHA1_LENGTH );
- if (binary_length != SHA1_LENGTH) {
- PORT_Free(dig);
- return JAR_ERR_CORRUPT;
- }
- memcpy (dig->sha1, binary_digest, SHA1_LENGTH);
- dig->sha1_status = jarHashPresent;
- }
-
- PORT_Assert( type == jarTypeMF || type == jarTypeSF );
- if (type == jarTypeMF) {
- ADDITEM (jar->hashes, jarTypeMF, x_name, dig, sizeof (JAR_Digest));
- } else if (type == jarTypeSF) {
- ADDITEM (signer->sf, jarTypeSF, x_name, dig, sizeof (JAR_Digest));
- } else {
- PORT_Free(dig);
- return JAR_ERR_ORDER;
- }
-
- /* we're placing these calculated digests of manifest.mf
- sections in a list where they can subsequently be forgotten */
- if (type == jarTypeMF && mfdig) {
- ADDITEM (jar->manifest, jarTypeSect,
- x_name, mfdig, sizeof (JAR_Digest));
- mfdig = NULL;
- }
-
- /* Retrieve our saved SHA1 digest from saved copy and check digests.
- This is just comparing the digest of the MF section as indicated in
- the SF file with the one we remembered from parsing the MF file */
-
- if (type == jarTypeSF) {
- if ((status = jar_internal_digest(jar, path, x_name, dig)) < 0)
- return status;
- }
+ *x_md5 = 0;
+ *x_sha = 0;
+ *x_name = 0;
+
+ /* If this is a manifest file, attempt to get a digest of the following
+ section, without damaging it. This digest will be saved later. */
+
+ if (type == jarTypeMF) {
+ char *sec;
+ long sec_len = raw_len;
+
+ if (!*raw_manifest || *raw_manifest == '\n') {
+ /* skip the blank line */
+ sec = jar_eat_line(1, PR_FALSE, raw_manifest, &sec_len);
+ } else
+ sec = raw_manifest;
+
+ if (sec_len > 0 && !PORT_Strncasecmp(sec, "Name:", 5)) {
+ if (type == jarTypeMF)
+ mfdig = jar_digest_section(sec, sec_len);
+ else
+ mfdig = NULL;
+ }
+ }
+
+ while (raw_len > 0) {
+ raw_manifest = jar_eat_line(1, PR_TRUE, raw_manifest, &raw_len);
+ if (raw_len <= 0 || !*raw_manifest)
+ break; /* blank line, done with this entry */
+
+ if (PORT_Strlen(raw_manifest) >= SZ) {
+ /* almost certainly nonsense */
+ continue;
+ }
+
+ /* Parse out the name/value pair */
+ PORT_Strcpy(line, raw_manifest);
+ x_info = line;
+
+ while (*x_info && *x_info != ' ' && *x_info != '\t' &&
+ *x_info != ':')
+ x_info++;
+
+ if (*x_info)
+ *x_info++ = 0;
+
+ while (*x_info == ' ' || *x_info == '\t')
+ x_info++;
+
+ if (!PORT_Strcasecmp(line, "Name"))
+ PORT_Strcpy(x_name, x_info);
+ else if (!PORT_Strcasecmp(line, "MD5-Digest"))
+ PORT_Strcpy(x_md5, x_info);
+ else if (!PORT_Strcasecmp(line, "SHA1-Digest") ||
+ !PORT_Strcasecmp(line, "SHA-Digest"))
+ PORT_Strcpy(x_sha, x_info);
+
+ /* Algorithm list is meta info we don't care about; keeping it out
+ of metadata saves significant space for large jar files */
+ else if (!PORT_Strcasecmp(line, "Digest-Algorithms") ||
+ !PORT_Strcasecmp(line, "Hash-Algorithms"))
+ continue;
+
+ /* Meta info is only collected for the manifest.mf file,
+ since the JAR_get_metainfo call does not support identity */
+ else if (type == jarTypeMF) {
+ JAR_Metainfo *met;
+
+ /* this is meta-data */
+ met = PORT_ZNew(JAR_Metainfo);
+ if (met == NULL)
+ return JAR_ERR_MEMORY;
+
+ /* metainfo (name, value) pair is now (line, x_info) */
+ if ((met->header = PORT_Strdup(line)) == NULL) {
+ PORT_Free(met);
+ return JAR_ERR_MEMORY;
+ }
+
+ if ((met->info = PORT_Strdup(x_info)) == NULL) {
+ PORT_Free(met->header);
+ PORT_Free(met);
+ return JAR_ERR_MEMORY;
+ }
+
+ ADDITEM(jar->metainfo, jarTypeMeta,
+ x_name, met, sizeof(JAR_Metainfo));
+ }
+ }
+
+ if (!*x_name) {
+ /* Whatever that was, it wasn't an entry, because we didn't get a
+ name. We don't really have anything, so don't record this. */
+ continue;
+ }
+
+ dig = PORT_ZNew(JAR_Digest);
+ if (dig == NULL)
+ return JAR_ERR_MEMORY;
+
+ if (*x_md5) {
+ unsigned int binary_length;
+ unsigned char *binary_digest;
+
+ binary_digest = ATOB_AsciiToData(x_md5, &binary_length);
+ PORT_Assert(binary_length == MD5_LENGTH);
+ if (binary_length != MD5_LENGTH) {
+ PORT_Free(dig);
+ return JAR_ERR_CORRUPT;
+ }
+ memcpy(dig->md5, binary_digest, MD5_LENGTH);
+ dig->md5_status = jarHashPresent;
+ }
+
+ if (*x_sha) {
+ unsigned int binary_length;
+ unsigned char *binary_digest;
+
+ binary_digest = ATOB_AsciiToData(x_sha, &binary_length);
+ PORT_Assert(binary_length == SHA1_LENGTH);
+ if (binary_length != SHA1_LENGTH) {
+ PORT_Free(dig);
+ return JAR_ERR_CORRUPT;
+ }
+ memcpy(dig->sha1, binary_digest, SHA1_LENGTH);
+ dig->sha1_status = jarHashPresent;
+ }
+
+ PORT_Assert(type == jarTypeMF || type == jarTypeSF);
+ if (type == jarTypeMF) {
+ ADDITEM(jar->hashes, jarTypeMF, x_name, dig, sizeof(JAR_Digest));
+ } else if (type == jarTypeSF) {
+ ADDITEM(signer->sf, jarTypeSF, x_name, dig, sizeof(JAR_Digest));
+ } else {
+ PORT_Free(dig);
+ return JAR_ERR_ORDER;
+ }
+
+ /* we're placing these calculated digests of manifest.mf
+ sections in a list where they can subsequently be forgotten */
+ if (type == jarTypeMF && mfdig) {
+ ADDITEM(jar->manifest, jarTypeSect,
+ x_name, mfdig, sizeof(JAR_Digest));
+ mfdig = NULL;
+ }
+
+ /* Retrieve our saved SHA1 digest from saved copy and check digests.
+ This is just comparing the digest of the MF section as indicated in
+ the SF file with the one we remembered from parsing the MF file */
+
+ if (type == jarTypeSF) {
+ if ((status = jar_internal_digest(jar, path, x_name, dig)) < 0)
+ return status;
+ }
}
return 0;
@@ -571,45 +567,45 @@ jar_internal_digest(JAR *jar, const char *path, char *x_name, JAR_Digest *dig)
savdig = jar_get_mf_digest(jar, x_name);
if (savdig == NULL) {
- /* no .mf digest for this pathname */
- status = jar_signal(JAR_ERR_ENTRY, jar, path, x_name);
- if (status < 0)
- return 0; /* was continue; */
- return status;
+ /* no .mf digest for this pathname */
+ status = jar_signal(JAR_ERR_ENTRY, jar, path, x_name);
+ if (status < 0)
+ return 0; /* was continue; */
+ return status;
}
/* check for md5 consistency */
if (dig->md5_status) {
- cv = PORT_Memcmp(savdig->md5, dig->md5, MD5_LENGTH);
- /* md5 hash of .mf file is not what expected */
- if (cv) {
- status = jar_signal(JAR_ERR_HASH, jar, path, x_name);
-
- /* bad hash, man */
- dig->md5_status = jarHashBad;
- savdig->md5_status = jarHashBad;
-
- if (status < 0)
- return 0; /* was continue; */
- return status;
- }
+ cv = PORT_Memcmp(savdig->md5, dig->md5, MD5_LENGTH);
+ /* md5 hash of .mf file is not what expected */
+ if (cv) {
+ status = jar_signal(JAR_ERR_HASH, jar, path, x_name);
+
+ /* bad hash, man */
+ dig->md5_status = jarHashBad;
+ savdig->md5_status = jarHashBad;
+
+ if (status < 0)
+ return 0; /* was continue; */
+ return status;
+ }
}
/* check for sha1 consistency */
if (dig->sha1_status) {
- cv = PORT_Memcmp(savdig->sha1, dig->sha1, SHA1_LENGTH);
- /* sha1 hash of .mf file is not what expected */
- if (cv) {
- status = jar_signal(JAR_ERR_HASH, jar, path, x_name);
-
- /* bad hash, man */
- dig->sha1_status = jarHashBad;
- savdig->sha1_status = jarHashBad;
-
- if (status < 0)
- return 0; /* was continue; */
- return status;
- }
+ cv = PORT_Memcmp(savdig->sha1, dig->sha1, SHA1_LENGTH);
+ /* sha1 hash of .mf file is not what expected */
+ if (cv) {
+ status = jar_signal(JAR_ERR_HASH, jar, path, x_name);
+
+ /* bad hash, man */
+ dig->sha1_status = jarHashBad;
+ savdig->sha1_status = jarHashBad;
+
+ if (status < 0)
+ return 0; /* was continue; */
+ return status;
+ }
}
return 0;
}
@@ -631,10 +627,10 @@ jar_insanity_check(char *data, long length)
long off;
for (off = 0; off < length; off++) {
- c = data [off];
- if (c == '\n' || c == '\r' || (c >= ' ' && c <= 128))
- continue;
- return JAR_ERR_CORRUPT;
+ c = data[off];
+ if (c == '\n' || c == '\r' || (c >= ' ' && c <= 128))
+ continue;
+ return JAR_ERR_CORRUPT;
}
return 0;
}
@@ -649,9 +645,9 @@ jar_insanity_check(char *data, long length)
*/
static int
jar_parse_digital_signature(char *raw_manifest, JAR_Signer *signer,
- long length, JAR *jar)
+ long length, JAR *jar)
{
- return jar_validate_pkcs7 (jar, signer, raw_manifest, length);
+ return jar_validate_pkcs7(jar, signer, raw_manifest, length);
}
/*
@@ -670,33 +666,33 @@ jar_add_cert(JAR *jar, JAR_Signer *signer, int type, CERTCertificate *cert)
unsigned char *keyData;
if (cert == NULL)
- return JAR_ERR_ORDER;
+ return JAR_ERR_ORDER;
fing = PORT_ZNew(JAR_Cert);
if (fing == NULL)
- goto loser;
+ goto loser;
- fing->cert = CERT_DupCertificate (cert);
+ fing->cert = CERT_DupCertificate(cert);
/* get the certkey */
fing->length = cert->derIssuer.len + 2 + cert->serialNumber.len;
- fing->key = keyData = (unsigned char *) PORT_ZAlloc(fing->length);
+ fing->key = keyData = (unsigned char *)PORT_ZAlloc(fing->length);
if (fing->key == NULL)
- goto loser;
+ goto loser;
keyData[0] = ((cert->derIssuer.len) >> 8) & 0xff;
keyData[1] = ((cert->derIssuer.len) & 0xff);
PORT_Memcpy(&keyData[2], cert->derIssuer.data, cert->derIssuer.len);
- PORT_Memcpy(&keyData[2+cert->derIssuer.len], cert->serialNumber.data,
- cert->serialNumber.len);
+ PORT_Memcpy(&keyData[2 + cert->derIssuer.len], cert->serialNumber.data,
+ cert->serialNumber.len);
- ADDITEM (signer->certs, type, NULL, fing, sizeof (JAR_Cert));
+ ADDITEM(signer->certs, type, NULL, fing, sizeof(JAR_Cert));
return 0;
loser:
if (fing) {
- if (fing->cert)
- CERT_DestroyCertificate (fing->cert);
- PORT_Free(fing);
+ if (fing->cert)
+ CERT_DestroyCertificate(fing->cert);
+ PORT_Free(fing);
}
return JAR_ERR_MEMORY;
}
@@ -710,10 +706,10 @@ loser:
* the input. NUL characters are treated as end-of-line characters,
* not as end-of-input characters. The input is NOT NUL terminated.
* Note: presently, all callers pass either 0 or 1 for lines.
- * 2) After skipping the specified number of input lines, if "eating" is
+ * 2) After skipping the specified number of input lines, if "eating" is
* non-zero, it finds the end of the next line of input and replaces
* the end of line character(s) with a NUL character.
- * This function modifies the input buffer, containing the file, in place.
+ * This function modifies the input buffer, containing the file, in place.
* This function handles PC, Mac, and Unix style text files.
* On entry, *len contains the maximum number of characters that this
* function should ever examine, starting with the character in *data.
@@ -729,43 +725,43 @@ jar_eat_line(int lines, int eating, char *data, long *len)
long maxLen = *len;
if (maxLen <= 0)
- return start;
+ return start;
#define GO_ON ((data - start) < maxLen)
/* Eat the requisite number of lines, if any;
prior to terminating the current line with a 0. */
- for (/* yip */ ; lines > 0; lines--) {
- while (GO_ON && *data && *data != '\r' && *data != '\n')
- data++;
+ for (/* yip */; lines > 0; lines--) {
+ while (GO_ON && *data && *data != '\r' && *data != '\n')
+ data++;
- /* Eat any leading CR */
- if (GO_ON && *data == '\r')
- data++;
+ /* Eat any leading CR */
+ if (GO_ON && *data == '\r')
+ data++;
- /* After the CR, ok to eat one LF */
- if (GO_ON && *data == '\n')
- data++;
+ /* After the CR, ok to eat one LF */
+ if (GO_ON && *data == '\n')
+ data++;
- /* If there are NULs, this function probably put them there */
- while (GO_ON && !*data)
- data++;
+ /* If there are NULs, this function probably put them there */
+ while (GO_ON && !*data)
+ data++;
}
- maxLen -= data - start; /* we have this many characters left. */
- *len = maxLen;
- start = data; /* now start again here. */
+ maxLen -= data - start; /* we have this many characters left. */
+ *len = maxLen;
+ start = data; /* now start again here. */
if (maxLen > 0 && eating) {
- /* Terminate this line with a 0 */
- while (GO_ON && *data && *data != '\n' && *data != '\r')
- data++;
+ /* Terminate this line with a 0 */
+ while (GO_ON && *data && *data != '\n' && *data != '\r')
+ data++;
- /* If not past the end, we are allowed to eat one CR */
- if (GO_ON && *data == '\r')
- *data++ = 0;
+ /* If not past the end, we are allowed to eat one CR */
+ if (GO_ON && *data == '\r')
+ *data++ = 0;
- /* After the CR (if any), if not past the end, ok to eat one LF */
- if (GO_ON && *data == '\n')
- *data++ = 0;
+ /* After the CR (if any), if not past the end, ok to eat one LF */
+ if (GO_ON && *data == '\n')
+ *data++ = 0;
}
return start;
}
@@ -788,11 +784,11 @@ jar_digest_section(char *manifest, long length)
global_len = length;
while (global_len > 0) {
- global_end = jar_eat_line(1, PR_FALSE, global_end, &global_len);
- if (global_len > 0 && (*global_end == 0 || *global_end == '\n'))
- break;
+ global_end = jar_eat_line(1, PR_FALSE, global_end, &global_len);
+ if (global_len > 0 && (*global_end == 0 || *global_end == '\n'))
+ break;
}
- return JAR_calculate_digest (manifest, global_end - manifest);
+ return JAR_calculate_digest(manifest, global_end - manifest);
}
/*
@@ -812,45 +808,38 @@ JAR_verify_digest(JAR *jar, const char *name, JAR_Digest *dig)
int result1 = 0;
int result2 = 0;
-
if (jar->valid < 0) {
- /* signature not valid */
- return JAR_ERR_SIG;
+ /* signature not valid */
+ return JAR_ERR_SIG;
}
- if (ZZ_ListEmpty (list)) {
- /* empty list */
- return JAR_ERR_PNF;
+ if (ZZ_ListEmpty(list)) {
+ /* empty list */
+ return JAR_ERR_PNF;
}
- for (link = ZZ_ListHead (list);
- !ZZ_ListIterDone (list, link);
- link = link->next) {
- it = link->thing;
- if (it->type == jarTypeMF
- && it->pathname && !PORT_Strcmp(it->pathname, name)) {
- shindig = (JAR_Digest *) it->data;
- if (shindig->md5_status) {
- if (shindig->md5_status == jarHashBad)
- return JAR_ERR_HASH;
- result1 = memcmp (dig->md5, shindig->md5, MD5_LENGTH);
- }
- if (shindig->sha1_status) {
- if (shindig->sha1_status == jarHashBad)
- return JAR_ERR_HASH;
- result2 = memcmp (dig->sha1, shindig->sha1, SHA1_LENGTH);
- }
- return (result1 == 0 && result2 == 0) ? 0 : JAR_ERR_HASH;
- }
+ for (link = ZZ_ListHead(list);
+ !ZZ_ListIterDone(list, link);
+ link = link->next) {
+ it = link->thing;
+ if (it->type == jarTypeMF &&
+ it->pathname && !PORT_Strcmp(it->pathname, name)) {
+ shindig = (JAR_Digest *)it->data;
+ if (shindig->md5_status) {
+ if (shindig->md5_status == jarHashBad)
+ return JAR_ERR_HASH;
+ result1 = memcmp(dig->md5, shindig->md5, MD5_LENGTH);
+ }
+ if (shindig->sha1_status) {
+ if (shindig->sha1_status == jarHashBad)
+ return JAR_ERR_HASH;
+ result2 = memcmp(dig->sha1, shindig->sha1, SHA1_LENGTH);
+ }
+ return (result1 == 0 && result2 == 0) ? 0 : JAR_ERR_HASH;
+ }
}
return JAR_ERR_PNF;
}
-
-
-
-
-
-
/*
* J A R _ f e t c h _ c e r t
*
@@ -869,13 +858,13 @@ JAR_fetch_cert(long length, void *key)
certdb = JAR_open_database();
if (certdb) {
- unsigned char *keyData = (unsigned char *)key;
- issuerSN.derIssuer.len = (keyData[0] << 8) + keyData[0];
- issuerSN.derIssuer.data = &keyData[2];
- issuerSN.serialNumber.len = length - (2 + issuerSN.derIssuer.len);
- issuerSN.serialNumber.data = &keyData[2+issuerSN.derIssuer.len];
- cert = CERT_FindCertByIssuerAndSN (certdb, &issuerSN);
- JAR_close_database (certdb);
+ unsigned char *keyData = (unsigned char *)key;
+ issuerSN.derIssuer.len = (keyData[0] << 8) + keyData[0];
+ issuerSN.derIssuer.data = &keyData[2];
+ issuerSN.serialNumber.len = length - (2 + issuerSN.derIssuer.len);
+ issuerSN.serialNumber.data = &keyData[2 + issuerSN.derIssuer.len];
+ cert = CERT_FindCertByIssuerAndSN(certdb, &issuerSN);
+ JAR_close_database(certdb);
}
return cert;
}
@@ -895,18 +884,18 @@ jar_get_mf_digest(JAR *jar, char *pathname)
ZZLink *link;
ZZList *list = jar->manifest;
- if (ZZ_ListEmpty (list))
- return NULL;
-
- for (link = ZZ_ListHead (list);
- !ZZ_ListIterDone (list, link);
- link = link->next) {
- it = link->thing;
- if (it->type == jarTypeSect
- && it->pathname && !PORT_Strcmp(it->pathname, pathname)) {
- dig = (JAR_Digest *) it->data;
- return dig;
- }
+ if (ZZ_ListEmpty(list))
+ return NULL;
+
+ for (link = ZZ_ListHead(list);
+ !ZZ_ListIterDone(list, link);
+ link = link->next) {
+ it = link->thing;
+ if (it->type == jarTypeSect &&
+ it->pathname && !PORT_Strcmp(it->pathname, pathname)) {
+ dig = (JAR_Digest *)it->data;
+ return dig;
+ }
}
return NULL;
}
@@ -924,21 +913,21 @@ jar_basename(const char *path)
char *pith, *e, *basename, *ext;
if (path == NULL)
- return PORT_Strdup("");
+ return PORT_Strdup("");
pith = PORT_Strdup(path);
basename = pith;
while (1) {
- for (e = basename; *e && *e != '/' && *e != '\\'; e++)
- /* yip */ ;
- if (*e)
- basename = ++e;
- else
- break;
+ for (e = basename; *e && *e != '/' && *e != '\\'; e++)
+ /* yip */;
+ if (*e)
+ basename = ++e;
+ else
+ break;
}
if ((ext = PORT_Strrchr(basename, '.')) != NULL)
- *ext = 0;
+ *ext = 0;
/* We already have the space allocated */
PORT_Strcpy(pith, basename);
@@ -968,7 +957,7 @@ static void
jar_catch_bytes(void *arg, const char *buf, unsigned long len)
{
/* Actually this should never be called, since there is
- presumably no data in the signature itself. */
+ presumably no data in the signature itself. */
}
/*
@@ -978,7 +967,7 @@ jar_catch_bytes(void *arg, const char *buf, unsigned long len)
* signature in DER format.
*
*/
-static int
+static int
jar_validate_pkcs7(JAR *jar, JAR_Signer *signer, char *data, long length)
{
@@ -988,35 +977,35 @@ jar_validate_pkcs7(JAR *jar, JAR_Signer *signer, char *data, long length)
int status = 0;
SECItem detdig;
- PORT_Assert( jar != NULL && signer != NULL );
+ PORT_Assert(jar != NULL && signer != NULL);
if (jar == NULL || signer == NULL)
- return JAR_ERR_ORDER;
+ return JAR_ERR_ORDER;
signer->valid = JAR_ERR_SIG;
/* We need a context if we can get one */
dcx = SEC_PKCS7DecoderStart(jar_catch_bytes, NULL /*cb_arg*/,
- NULL /*getpassword*/, jar->mw,
- NULL, NULL, NULL);
+ NULL /*getpassword*/, jar->mw,
+ NULL, NULL, NULL);
if (dcx == NULL) {
- /* strange pkcs7 failure */
- return JAR_ERR_PK7;
+ /* strange pkcs7 failure */
+ return JAR_ERR_PK7;
}
- SEC_PKCS7DecoderUpdate (dcx, data, length);
- cinfo = SEC_PKCS7DecoderFinish (dcx);
+ SEC_PKCS7DecoderUpdate(dcx, data, length);
+ cinfo = SEC_PKCS7DecoderFinish(dcx);
if (cinfo == NULL) {
- /* strange pkcs7 failure */
- return JAR_ERR_PK7;
+ /* strange pkcs7 failure */
+ return JAR_ERR_PK7;
}
- if (SEC_PKCS7ContentIsEncrypted (cinfo)) {
- /* content was encrypted, fail */
- return JAR_ERR_PK7;
+ if (SEC_PKCS7ContentIsEncrypted(cinfo)) {
+ /* content was encrypted, fail */
+ return JAR_ERR_PK7;
}
- if (SEC_PKCS7ContentIsSigned (cinfo) == PR_FALSE) {
- /* content was not signed, fail */
- return JAR_ERR_PK7;
+ if (SEC_PKCS7ContentIsSigned(cinfo) == PR_FALSE) {
+ /* content was not signed, fail */
+ return JAR_ERR_PK7;
}
PORT_SetError(0);
@@ -1025,20 +1014,20 @@ jar_validate_pkcs7(JAR *jar, JAR_Signer *signer, char *data, long length)
detdig.len = SHA1_LENGTH;
detdig.data = signer->digest->sha1;
goodSig = SEC_PKCS7VerifyDetachedSignature(cinfo,
- certUsageObjectSigner,
- &detdig, HASH_AlgSHA1,
- PR_FALSE);
+ certUsageObjectSigner,
+ &detdig, HASH_AlgSHA1,
+ PR_FALSE);
jar_gather_signers(jar, signer, cinfo);
if (goodSig == PR_TRUE) {
- /* signature is valid */
- signer->valid = 0;
+ /* signature is valid */
+ signer->valid = 0;
} else {
- status = PORT_GetError();
- PORT_Assert( status < 0 );
- if (status >= 0)
- status = JAR_ERR_SIG;
- jar->valid = status;
- signer->valid = status;
+ status = PORT_GetError();
+ PORT_Assert(status < 0);
+ if (status >= 0)
+ status = JAR_ERR_SIG;
+ jar->valid = status;
+ signer->valid = status;
}
jar->pkcs7 = PR_TRUE;
signer->pkcs7 = PR_TRUE;
@@ -1063,25 +1052,25 @@ jar_gather_signers(JAR *jar, JAR_Signer *signer, SEC_PKCS7ContentInfo *cinfo)
SEC_PKCS7SignerInfo **pksigners, *pksigner;
if (sdp == NULL)
- return JAR_ERR_PK7;
+ return JAR_ERR_PK7;
pksigners = sdp->signerInfos;
/* permit exactly one signer */
- if (pksigners == NULL || pksigners [0] == NULL || pksigners [1] != NULL)
- return JAR_ERR_PK7;
+ if (pksigners == NULL || pksigners[0] == NULL || pksigners[1] != NULL)
+ return JAR_ERR_PK7;
pksigner = *pksigners;
cert = pksigner->cert;
if (cert == NULL)
- return JAR_ERR_PK7;
+ return JAR_ERR_PK7;
certdb = JAR_open_database();
if (certdb == NULL)
- return JAR_ERR_GENERAL;
+ return JAR_ERR_GENERAL;
result = jar_add_cert(jar, signer, jarTypeSign, cert);
- JAR_close_database (certdb);
+ JAR_close_database(certdb);
return result;
}
@@ -1105,13 +1094,12 @@ JAR_open_database(void)
* For use by JAR functions.
*
*/
-int
+int
JAR_close_database(CERTCertDBHandle *certdb)
{
return 0;
}
-
/*
* j a r _ s i g n a l
*
@@ -1121,10 +1109,10 @@ JAR_close_database(CERTCertDBHandle *certdb)
static int
jar_signal(int status, JAR *jar, const char *metafile, char *pathname)
{
- char *errstring = JAR_get_error (status);
+ char *errstring = JAR_get_error(status);
if (jar->signal) {
- (*jar->signal) (status, jar, metafile, pathname, errstring);
- return 0;
+ (*jar->signal)(status, jar, metafile, pathname, errstring);
+ return 0;
}
return status;
}
@@ -1143,28 +1131,28 @@ jar_append(ZZList *list, int type, char *pathname, void *data, size_t size)
ZZLink *entity;
if (it == NULL)
- goto loser;
+ goto loser;
if (pathname) {
- it->pathname = PORT_Strdup(pathname);
- if (it->pathname == NULL)
- goto loser;
+ it->pathname = PORT_Strdup(pathname);
+ if (it->pathname == NULL)
+ goto loser;
}
it->type = (jarType)type;
- it->data = (unsigned char *) data;
+ it->data = (unsigned char *)data;
it->size = size;
- entity = ZZ_NewLink (it);
+ entity = ZZ_NewLink(it);
if (entity) {
- ZZ_AppendLink (list, entity);
- return 0;
+ ZZ_AppendLink(list, entity);
+ return 0;
}
loser:
if (it) {
- if (it->pathname)
- PORT_Free(it->pathname);
- PORT_Free(it);
+ if (it->pathname)
+ PORT_Free(it->pathname);
+ PORT_Free(it);
}
return JAR_ERR_MEMORY;
}
diff --git a/lib/jar/jzconf.h b/lib/jar/jzconf.h
index 59012e26a..7687eb3a5 100644
--- a/lib/jar/jzconf.h
+++ b/lib/jar/jzconf.h
@@ -1,6 +1,6 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-1996 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
+ * For conditions of distribution and use, see copyright notice in zlib.h
*/
/* This file was modified since it was taken from the zlib distribution */
@@ -12,49 +12,49 @@
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
-# define deflateInit_ z_deflateInit_
-# define deflate z_deflate
-# define deflateEnd z_deflateEnd
-# define inflateInit_ z_inflateInit_
-# define inflate z_inflate
-# define inflateEnd z_inflateEnd
-# define deflateInit2_ z_deflateInit2_
-# define deflateSetDictionary z_deflateSetDictionary
-# define deflateCopy z_deflateCopy
-# define deflateReset z_deflateReset
-# define deflateParams z_deflateParams
-# define inflateInit2_ z_inflateInit2_
-# define inflateSetDictionary z_inflateSetDictionary
-# define inflateSync z_inflateSync
-# define inflateReset z_inflateReset
-# define compress z_compress
-# define uncompress z_uncompress
-# define adler32 z_adler32
-# define crc32 z_crc32
-# define get_crc_table z_get_crc_table
-
-# define Byte z_Byte
-# define uInt z_uInt
-# define uLong z_uLong
-# define Bytef z_Bytef
-# define charf z_charf
-# define intf z_intf
-# define uIntf z_uIntf
-# define uLongf z_uLongf
-# define voidpf z_voidpf
-# define voidp z_voidp
+#define deflateInit_ z_deflateInit_
+#define deflate z_deflate
+#define deflateEnd z_deflateEnd
+#define inflateInit_ z_inflateInit_
+#define inflate z_inflate
+#define inflateEnd z_inflateEnd
+#define deflateInit2_ z_deflateInit2_
+#define deflateSetDictionary z_deflateSetDictionary
+#define deflateCopy z_deflateCopy
+#define deflateReset z_deflateReset
+#define deflateParams z_deflateParams
+#define inflateInit2_ z_inflateInit2_
+#define inflateSetDictionary z_inflateSetDictionary
+#define inflateSync z_inflateSync
+#define inflateReset z_inflateReset
+#define compress z_compress
+#define uncompress z_uncompress
+#define adler32 z_adler32
+#define crc32 z_crc32
+#define get_crc_table z_get_crc_table
+
+#define Byte z_Byte
+#define uInt z_uInt
+#define uLong z_uLong
+#define Bytef z_Bytef
+#define charf z_charf
+#define intf z_intf
+#define uIntf z_uIntf
+#define uLongf z_uLongf
+#define voidpf z_voidpf
+#define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
-# define WIN32
+#define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
-# ifndef __32BIT__
-# define __32BIT__
-# endif
+#ifndef __32BIT__
+#define __32BIT__
+#endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
-# define MSDOS
+#define MSDOS
#endif
/*
@@ -62,42 +62,42 @@
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#if defined(MSDOS) && !defined(__32BIT__)
-# define MAXSEG_64K
+#define MAXSEG_64K
#endif
#ifdef MSDOS
-# define UNALIGNED_OK
+#define UNALIGNED_OK
#endif
-#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32) || defined(XP_OS2)) && !defined(STDC)
-# define STDC
+#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32) || defined(XP_OS2)) && !defined(STDC)
+#define STDC
#endif
#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
-# define STDC
+#define STDC
#endif
#ifndef STDC
-# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
-# define const
-# endif
+#ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+#define const
+#endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
-#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
-# define NO_DUMMY_DECL
+#if defined(__MWERKS__) || defined(applec) || defined(THINK_C) || defined(__SC__)
+#define NO_DUMMY_DECL
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
-# ifdef MAXSEG_64K
-# define MAX_MEM_LEVEL 8
-# else
-# define MAX_MEM_LEVEL 9
-# endif
+#ifdef MAXSEG_64K
+#define MAX_MEM_LEVEL 8
+#else
+#define MAX_MEM_LEVEL 9
+#endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
#ifndef MAX_WBITS
-# define MAX_WBITS 15 /* 32K LZ77 window */
+#define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
@@ -113,14 +113,14 @@
for small objects.
*/
- /* Type declarations */
+/* Type declarations */
#ifndef OF /* function prototypes */
-# ifdef STDC
-# define OF(args) args
-# else
-# define OF(args) ()
-# endif
+#ifdef STDC
+#define OF(args) args
+#else
+#define OF(args) ()
+#endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
@@ -130,45 +130,45 @@
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
- /* MSC small or medium model */
-# define SMALL_MEDIUM
-# ifdef _MSC_VER
-# define FAR __far
-# else
-# define FAR far
-# endif
+/* MSC small or medium model */
+#define SMALL_MEDIUM
+#ifdef _MSC_VER
+#define FAR __far
+#else
+#define FAR far
+#endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
-# ifndef __32BIT__
-# define SMALL_MEDIUM
-# define FAR __far
-# endif
+#ifndef __32BIT__
+#define SMALL_MEDIUM
+#define FAR __far
+#endif
#endif
#ifndef FAR
-# define FAR
+#define FAR
#endif
-typedef unsigned char Byte; /* 8 bits */
-typedef unsigned int uInt; /* 16 bits or more */
-typedef unsigned long uLong; /* 32 bits or more */
+typedef unsigned char Byte; /* 8 bits */
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
#if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
- /* Borland C/C++ ignores FAR inside typedef */
-# define Bytef Byte FAR
+/* Borland C/C++ ignores FAR inside typedef */
+#define Bytef Byte FAR
#else
- typedef Byte FAR Bytef;
+typedef Byte FAR Bytef;
#endif
-typedef char FAR charf;
-typedef int FAR intf;
-typedef uInt FAR uIntf;
+typedef char FAR charf;
+typedef int FAR intf;
+typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
- typedef void FAR *voidpf;
- typedef void *voidp;
+typedef void FAR *voidpf;
+typedef void *voidp;
#else
- typedef Byte FAR *voidpf;
- typedef Byte *voidp;
+typedef Byte FAR *voidpf;
+typedef Byte *voidp;
#endif
#ifdef MOZILLA_CLIENT
@@ -176,10 +176,10 @@ typedef uLong FAR uLongf;
#else
/* Compile with -DZLIB_DLL for Windows DLL support */
#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
-# include <windows.h>
-# define EXPORT WINAPI
+#include <windows.h>
+#define EXPORT WINAPI
#else
-# define EXPORT
+#define EXPORT
#endif
#define PR_PUBLIC_API(type) type
diff --git a/lib/jar/jzlib.h b/lib/jar/jzlib.h
index aa25c28bb..92d3d5b21 100644
--- a/lib/jar/jzlib.h
+++ b/lib/jar/jzlib.h
@@ -44,7 +44,7 @@ extern "C" {
#define ZLIB_VERSION "1.0.4"
-/*
+/*
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
@@ -68,30 +68,30 @@ extern "C" {
for some forms of corrupted input.
*/
-typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
-typedef void (*free_func) OF((voidpf opaque, voidpf address));
+typedef voidpf(*alloc_func) OF((voidpf opaque, uInt items, uInt size));
+typedef void(*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
- Bytef *next_in; /* next input byte */
- uInt avail_in; /* number of bytes available at next_in */
- uLong total_in; /* total nb of input bytes read so far */
+ Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ uLong total_in; /* total nb of input bytes read so far */
- Bytef *next_out; /* next output byte should be put there */
- uInt avail_out; /* remaining free space at next_out */
- uLong total_out; /* total nb of bytes output so far */
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ uLong total_out; /* total nb of bytes output so far */
- char *msg; /* last error message, NULL if no error */
+ char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
- alloc_func zalloc; /* used to allocate the internal state */
- free_func zfree; /* used to free the internal state */
- voidpf opaque; /* private data object passed to zalloc and zfree */
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree */
- int data_type; /* best guess about the data type: ascii or binary */
- uLong adler; /* adler32 value of the uncompressed data */
- uLong reserved; /* reserved for future use */
+ int data_type; /* best guess about the data type: ascii or binary */
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
@@ -125,58 +125,59 @@ typedef z_stream FAR *z_streamp;
a single step).
*/
- /* constants */
+/* constants */
-#define Z_NO_FLUSH 0
+#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1
-#define Z_SYNC_FLUSH 2
-#define Z_FULL_FLUSH 3
-#define Z_FINISH 4
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
/* Allowed flush values; see deflate() below for details */
-#define Z_OK 0
-#define Z_STREAM_END 1
-#define Z_NEED_DICT 2
-#define Z_ERRNO (-1)
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
-#define Z_DATA_ERROR (-3)
-#define Z_MEM_ERROR (-4)
-#define Z_BUF_ERROR (-5)
+#define Z_DATA_ERROR (-3)
+#define Z_MEM_ERROR (-4)
+#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
-#define Z_NO_COMPRESSION 0
-#define Z_BEST_SPEED 1
-#define Z_BEST_COMPRESSION 9
-#define Z_DEFAULT_COMPRESSION (-1)
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
-#define Z_FILTERED 1
-#define Z_HUFFMAN_ONLY 2
-#define Z_DEFAULT_STRATEGY 0
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
-#define Z_BINARY 0
-#define Z_ASCII 1
-#define Z_UNKNOWN 2
+#define Z_BINARY 0
+#define Z_ASCII 1
+#define Z_UNKNOWN 2
/* Possible values of the data_type field */
-#define Z_DEFLATED 8
+#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
-#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */
- /* basic functions */
+/* basic functions */
#ifdef MOZILLA_CLIENT
-PR_EXTERN(const char *) zlibVersion (void);
+PR_EXTERN(const char *)
+zlibVersion(void);
#else
-extern const char * EXPORT zlibVersion OF((void));
+extern const char *EXPORT zlibVersion OF((void));
#endif
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
@@ -184,7 +185,7 @@ extern const char * EXPORT zlibVersion OF((void));
This check is automatically made by deflateInit and inflateInit.
*/
-/*
+/*
extern int EXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields
@@ -206,9 +207,9 @@ extern int EXPORT deflateInit OF((z_streamp strm, int level));
perform any compression: this will be done by deflate().
*/
-
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) deflate (z_streamp strm, int flush);
+PR_EXTERN(int)
+deflate(z_streamp strm, int flush);
#else
extern int EXPORT deflate OF((z_streamp strm, int flush));
#endif
@@ -261,7 +262,7 @@ extern int EXPORT deflate OF((z_streamp strm, int flush));
more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the
stream are deflateReset or deflateEnd.
-
+
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least
0.1% larger than avail_in plus 12 bytes. If deflate does not return
@@ -279,9 +280,9 @@ extern int EXPORT deflate OF((z_streamp strm, int flush));
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
*/
-
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) deflateEnd (z_streamp strm);
+PR_EXTERN(int)
+deflateEnd(z_streamp strm);
#else
extern int EXPORT deflateEnd OF((z_streamp strm));
#endif
@@ -297,8 +298,7 @@ extern int EXPORT deflateEnd OF((z_streamp strm));
deallocated).
*/
-
-/*
+/*
extern int EXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields
@@ -313,9 +313,9 @@ extern int EXPORT inflateInit OF((z_streamp strm));
done by inflate().
*/
-
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) inflate (z_streamp strm, int flush);
+PR_EXTERN(int)
+inflate(z_streamp strm, int flush);
#else
extern int EXPORT inflate OF((z_streamp strm, int flush));
#endif
@@ -372,9 +372,9 @@ extern int EXPORT inflate OF((z_streamp strm, int flush));
dictionary chosen by the compressor.
*/
-
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) inflateEnd (z_streamp strm);
+PR_EXTERN(int)
+inflateEnd(z_streamp strm);
#else
extern int EXPORT inflateEnd OF((z_streamp strm));
#endif
@@ -388,13 +388,13 @@ extern int EXPORT inflateEnd OF((z_streamp strm));
static string (which must not be deallocated).
*/
- /* Advanced functions */
+/* Advanced functions */
/*
The following functions are needed only in some special applications.
*/
-/*
+/*
extern int EXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
@@ -450,17 +450,18 @@ extern int EXPORT deflateInit2 OF((z_streamp strm,
not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
an invalid method). msg is set to null if there is no error message.
deflateInit2 does not perform any compression: this will be done by
- deflate().
+ deflate().
*/
-
+
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) deflateSetDictionary (z_streamp strm,
- const Bytef *dictionary,
- uInt dictLength);
+PR_EXTERN(int)
+deflateSetDictionary(z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength);
#else
extern int EXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
- uInt dictLength));
+ uInt dictLength));
#endif
/*
Initializes the compression dictionary (history buffer) from the given
@@ -485,11 +486,12 @@ extern int EXPORT deflateSetDictionary OF((z_streamp strm,
parameter is invalid (such as NULL dictionary) or the stream state
is inconsistent (for example if deflate has already been called for this
stream). deflateSetDictionary does not perform any compression: this will
- be done by deflate().
+ be done by deflate().
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) deflateCopy (z_streamp dest, z_streamp source);
+PR_EXTERN(int)
+deflateCopy(z_streamp dest, z_streamp source);
#else
extern int EXPORT deflateCopy OF((z_streamp dest, z_streamp source));
#endif
@@ -515,7 +517,8 @@ extern int EXPORT deflateCopy OF((z_streamp dest, z_streamp source));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) deflateReset (z_streamp strm);
+PR_EXTERN(int)
+deflateReset(z_streamp strm);
#else
extern int EXPORT deflateReset OF((z_streamp strm));
#endif
@@ -530,7 +533,8 @@ extern int EXPORT deflateReset OF((z_streamp strm));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) deflateParams (z_streamp strm, int level, int strategy);
+PR_EXTERN(int)
+deflateParams(z_streamp strm, int level, int strategy);
#else
extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
#endif
@@ -551,7 +555,7 @@ extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
if strm->avail_out was zero.
*/
-/*
+/*
extern int EXPORT inflateInit2 OF((z_streamp strm,
int windowBits));
@@ -587,13 +591,14 @@ extern int EXPORT inflateInit2 OF((z_streamp strm,
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) inflateSetDictionary (z_streamp strm,
- const Bytef *dictionary,
- uInt dictLength);
+PR_EXTERN(int)
+inflateSetDictionary(z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength);
#else
extern int EXPORT inflateSetDictionary OF((z_streamp strm,
- const Bytef *dictionary,
- uInt dictLength));
+ const Bytef *dictionary,
+ uInt dictLength));
#endif
/*
Initializes the decompression dictionary (history buffer) from the given
@@ -612,11 +617,12 @@ extern int EXPORT inflateSetDictionary OF((z_streamp strm,
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) inflateSync (z_streamp strm);
+PR_EXTERN(int)
+inflateSync(z_streamp strm);
#else
extern int EXPORT inflateSync OF((z_streamp strm));
#endif
-/*
+/*
Skips invalid compressed data until the special marker (see deflate()
above) can be found, or until all available input is skipped. No output
is provided.
@@ -631,7 +637,8 @@ extern int EXPORT inflateSync OF((z_streamp strm));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) inflateReset (z_streamp strm);
+PR_EXTERN(int)
+inflateReset(z_streamp strm);
#else
extern int EXPORT inflateReset OF((z_streamp strm));
#endif
@@ -644,8 +651,7 @@ extern int EXPORT inflateReset OF((z_streamp strm));
stream state was inconsistent (such as zalloc or state being NULL).
*/
-
- /* utility functions */
+/* utility functions */
/*
The following utility functions are implemented on top of the
@@ -656,11 +662,12 @@ extern int EXPORT inflateReset OF((z_streamp strm));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) compress (Bytef *dest, uLongf *destLen,
- const Bytef *source, uLong sourceLen);
+PR_EXTERN(int)
+compress(Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen);
#else
-extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
- const Bytef *source, uLong sourceLen));
+extern int EXPORT compress OF((Bytef * dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
#endif
/*
Compresses the source buffer into the destination buffer. sourceLen is
@@ -676,11 +683,12 @@ extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) uncompress (Bytef *dest, uLongf *destLen,
- const Bytef *source, uLong sourceLen);
+PR_EXTERN(int)
+uncompress(Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen);
#else
-extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
- const Bytef *source, uLong sourceLen));
+extern int EXPORT uncompress OF((Bytef * dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
#endif
/*
Decompresses the source buffer into the destination buffer. sourceLen is
@@ -698,13 +706,13 @@ extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
-
typedef voidp gzFile;
#ifdef MOZILLA_CLIENT
-PR_EXTERN(gzFile) gzopen (const char *path, const char *mode);
+PR_EXTERN(gzFile)
+gzopen(const char *path, const char *mode);
#else
-extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
+extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
#endif
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
@@ -718,9 +726,10 @@ extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(gzFile) gzdopen (int fd, const char *mode);
+PR_EXTERN(gzFile)
+gzdopen(int fd, const char *mode);
#else
-extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
+extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
#endif
/*
gzdopen() associates a gzFile with the file descriptor fd. File
@@ -735,9 +744,10 @@ extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) gzread (gzFile file, voidp buf, unsigned len);
+PR_EXTERN(int)
+gzread(gzFile file, voidp buf, unsigned len);
#else
-extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
+extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
#endif
/*
Reads the given number of uncompressed bytes from the compressed file.
@@ -747,9 +757,10 @@ extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
end of file, -1 for error). */
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) gzwrite (gzFile file, const voidp buf, unsigned len);
+PR_EXTERN(int)
+gzwrite(gzFile file, const voidp buf, unsigned len);
#else
-extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
+extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
#endif
/*
Writes the given number of uncompressed bytes into the compressed file.
@@ -758,9 +769,10 @@ extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) gzflush (gzFile file, int flush);
+PR_EXTERN(int)
+gzflush(gzFile file, int flush);
#else
-extern int EXPORT gzflush OF((gzFile file, int flush));
+extern int EXPORT gzflush OF((gzFile file, int flush));
#endif
/*
Flushes all pending output into the compressed file. The parameter
@@ -772,9 +784,10 @@ extern int EXPORT gzflush OF((gzFile file, int flush));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) gzclose (gzFile file);
+PR_EXTERN(int)
+gzclose(gzFile file);
#else
-extern int EXPORT gzclose OF((gzFile file));
+extern int EXPORT gzclose OF((gzFile file));
#endif
/*
Flushes all pending output if necessary, closes the compressed file
@@ -783,9 +796,10 @@ extern int EXPORT gzclose OF((gzFile file));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(const char *) gzerror (gzFile file, int *errnum);
+PR_EXTERN(const char *)
+gzerror(gzFile file, int *errnum);
#else
-extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
+extern const char *EXPORT gzerror OF((gzFile file, int *errnum));
#endif
/*
Returns the error message for the last error which occurred on the
@@ -795,7 +809,7 @@ extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
to get the exact error code.
*/
- /* checksum functions */
+/* checksum functions */
/*
These functions are not related to compression but are exported
@@ -804,7 +818,8 @@ extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(uLong) adler32 (uLong adler, const Bytef *buf, uInt len);
+PR_EXTERN(uLong)
+adler32(uLong adler, const Bytef *buf, uInt len);
#else
extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
#endif
@@ -825,9 +840,10 @@ extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(uLong) crc32 (uLong crc, const Bytef *buf, uInt len);
+PR_EXTERN(uLong)
+crc32(uLong crc, const Bytef *buf, uInt len);
#else
-extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
+extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
#endif
/*
Update a running crc with the bytes buf[0..len-1] and return the updated
@@ -844,47 +860,51 @@ extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
if (crc != original_crc) error();
*/
-
- /* various hacks, don't look :) */
+/* various hacks, don't look :) */
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
#ifdef MOZILLA_CLIENT
-PR_EXTERN(int) deflateInit (z_streamp strm, int level, const char *version,
- int stream_size);
-PR_EXTERN(int) inflateInit_(z_streamp strm, const char *version,
- int stream_size);
-PR_EXTERN(int) deflateInit2_(z_streamp strm, int level, int method,
- int windowBits, int memLevel, int strategy,
- const char *version, int stream_size);
-PR_EXTERN(int) inflateInit2_(z_streamp strm, int windowBits,
- const char *version, int stream_size);
+PR_EXTERN(int)
+deflateInit(z_streamp strm, int level, const char *version,
+ int stream_size);
+PR_EXTERN(int)
+inflateInit_(z_streamp strm, const char *version,
+ int stream_size);
+PR_EXTERN(int)
+deflateInit2_(z_streamp strm, int level, int method,
+ int windowBits, int memLevel, int strategy,
+ const char *version, int stream_size);
+PR_EXTERN(int)
+inflateInit2_(z_streamp strm, int windowBits,
+ const char *version, int stream_size);
#else
-extern int EXPORT deflateInit_ OF((z_streamp strm, int level, const char *version,
- int stream_size));
-extern int EXPORT inflateInit_ OF((z_streamp strm, const char *version,
- int stream_size));
-extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
- int windowBits, int memLevel, int strategy,
- const char *version, int stream_size));
-extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
- const char *version, int stream_size));
+extern int EXPORT deflateInit_ OF((z_streamp strm, int level, const char *version,
+ int stream_size));
+extern int EXPORT inflateInit_ OF((z_streamp strm, const char *version,
+ int stream_size));
+extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
+ int windowBits, int memLevel, int strategy,
+ const char *version, int stream_size));
+extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
+ const char *version, int stream_size));
#endif /* MOZILLA_CLIENT */
-
#define deflateInit(strm, level) \
- deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
+ deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
- inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
+ inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
- deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
- (strategy), ZLIB_VERSION, sizeof(z_stream))
+ deflateInit2_((strm), (level), (method), (windowBits), (memLevel), \
+ (strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
- inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
- struct internal_state {int dummy;}; /* hack for buggy compilers */
+struct internal_state {
+ int dummy;
+}; /* hack for buggy compilers */
#endif
uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */