summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrelyea%netscape.com <devnull@localhost>2005-11-15 01:49:01 +0000
committerrelyea%netscape.com <devnull@localhost>2005-11-15 01:49:01 +0000
commitc1646abd88c5f21362841fd227ae2376fb258728 (patch)
treea970434d04dc386a626eb652ac040318f4ed24f9
parent8bb7331b62bc9c3cbbf80274e9d164de9caa2119 (diff)
downloadnss-hg-c1646abd88c5f21362841fd227ae2376fb258728.tar.gz
Add loops, conditionals and simple math.
-rw-r--r--security/nss/cmd/pk11util/pk11table.c38
-rw-r--r--security/nss/cmd/pk11util/pk11util.c125
-rw-r--r--security/nss/cmd/pk11util/pk11util.h6
-rw-r--r--security/nss/cmd/pk11util/scripts/pkeybin1541 -> 1543 bytes
4 files changed, 164 insertions, 5 deletions
diff --git a/security/nss/cmd/pk11util/pk11table.c b/security/nss/cmd/pk11util/pk11table.c
index ffdb35cfc..1f1406a65 100644
--- a/security/nss/cmd/pk11util/pk11table.c
+++ b/security/nss/cmd/pk11util/pk11table.c
@@ -1221,6 +1221,13 @@ const Commands _commands[] = {
" size number of elements in the array\n",
{ArgVar|ArgNew, ArgVar, ArgULong, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
+ {"NewInitArg", F_NewInitializeArgs,
+"NewInitArg varName string\n\n"
+"Creates a new init variable.\n"
+" varName variable name of the new initArg\n"
+" string string parameter for init arg\n",
+ {ArgVar|ArgNew, ArgULong, ArgVar|ArgNew, ArgNone, ArgNone,
+ ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"NewTemplate", F_NewTemplate,
"NewTemplate varName attributeList\n\n"
"Create a new empty template and populate the attribute list\n"
@@ -1291,11 +1298,21 @@ const Commands _commands[] = {
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Restore", F_RestoreVar,
"Restore filename variable\n\n"
-"Restors a variable from a file\n"
+"Restores a variable from a file\n"
" fileName target file to restore the variable from\n"
" variable variable to restore\n",
{ArgVar|ArgNew, ArgVar, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
+ {"Increment", F_Increment,
+"Increment variable value\n\n"
+"Increment a variable by value\n",
+ {ArgVar, ArgULong, ArgNone, ArgNone, ArgNone,
+ ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
+ {"Decrement", F_Decrement,
+"Decrement variable value\n\n"
+"Decrement a variable by value\n",
+ {ArgVar, ArgULong, ArgNone, ArgNone, ArgNone,
+ ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"List", F_List,
"List all the variables\n",
{ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
@@ -1315,14 +1332,31 @@ const Commands _commands[] = {
{ArgVar|ArgFull, ArgNone, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"System", F_System,
- "Fix Me... ",
+ "Set System Flag",
{ArgULong, ArgNone, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
+ {"LoopRun", F_Loop,
+"LoopRun filename var start end step\n\n"
+"Run in a loop. Loop exit if scrip does and explicit quit (Quit QuitIf etc.)",
+ {ArgVar|ArgNew, ArgVar|ArgNew, ArgULong, ArgULong, ArgULong,
+ ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Help", F_Help,
"Help [command]\n\n"
"print general help, or help for a specific command\n",
{ArgVar|ArgOpt, ArgNone, ArgNone, ArgNone, ArgNone,
ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
+ {"QuitIf", F_QuitIf,
+"QuitIf arg1 comparator arg2\n\n"
+"Exit from this program if Condition is valid, valid comparators:\n"
+" < > <= >= = !=\n",
+ {ArgULong, ArgVar|ArgNew, ArgULong, ArgNone, ArgNone,
+ ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
+ {"QuitIfString", F_QuitIfString,
+"QuitIfString arg1 comparator arg2\n\n"
+"Exit from this program if Condition is valid, valid comparators:\n"
+" = !=\n",
+ {ArgVar|ArgNew, ArgVar|ArgNew, ArgVar|ArgNew, ArgNone, ArgNone,
+ ArgNone, ArgNone, ArgNone, ArgNone, ArgNone }},
{"Quit", F_Quit,
"Exit from this program",
{ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
diff --git a/security/nss/cmd/pk11util/pk11util.c b/security/nss/cmd/pk11util/pk11util.c
index ef5e2db12..3c8a1894f 100644
--- a/security/nss/cmd/pk11util/pk11util.c
+++ b/security/nss/cmd/pk11util/pk11util.c
@@ -220,6 +220,12 @@ argFreeData(Value *arg)
free(template[i].pValue);
}
}
+ if ((arg->type & ArgMask) == ArgInitializeArgs) {
+ CK_C_INITIALIZE_ARGS *init = (CK_C_INITIALIZE_ARGS *)arg->data;
+ if (init->LibraryParameters) {
+ free(init->LibraryParameters);
+ }
+ }
free(arg->data);
}
arg->type &= ~ArgStatic;
@@ -345,7 +351,7 @@ NewValue(ArgType type, CK_ULONG arraySize)
return NULL;
}
value->reference = 1;
- value->arraySize = arraySize;
+ value->arraySize = (type == ArgChar) ? 1: arraySize;
memset(value->data, 0, value->size);
return value;
@@ -735,6 +741,22 @@ NewMechanism(const char *bp, CK_ULONG mechType)
return CKR_OK;
}
+CK_RV
+NewInitializeArgs(const char *bp, CK_ULONG flags, const char *param)
+{
+ Value *value; /* new Value */
+ CK_C_INITIALIZE_ARGS *init;
+
+ value = NewValue(ArgInitializeArgs, 1);
+ init = (CK_C_INITIALIZE_ARGS *)value->data;
+ init->flags = flags;
+ if (strcmp(param, "null") != 0) {
+ init->LibraryParameters = (CK_CHAR_PTR *)strdup(param);
+ }
+ (void) AddVariable(bp, &value);
+ return CKR_OK;
+}
+
/*
* add a new variable to the chain
*/
@@ -933,6 +955,26 @@ save(const char *filename,Value *ptr)
return CKR_OK;
}
+static CK_RV
+increment(Value *ptr, CK_ULONG value)
+{
+ if ((ptr->type & ArgMask) != ArgULong) {
+ return CKR_ARGUMENTS_BAD;
+ }
+ *(CK_ULONG *)ptr->data += value;
+ return CKR_OK;
+}
+
+static CK_RV
+decrement(Value *ptr, CK_ULONG value)
+{
+ if ((ptr->type & ArgMask) != ArgULong) {
+ return CKR_ARGUMENTS_BAD;
+ }
+ *(CK_ULONG *)ptr->data -= value;
+ return CKR_OK;
+}
+
CK_RV
printArg(Value *ptr,int arg_number)
{
@@ -1104,6 +1146,9 @@ printArg(Value *ptr,int arg_number)
case ArgInitializeArgs:
initArgs = (CK_C_INITIALIZE_ARGS *)ptr->data;
printFlags(" Flags: ", initArgs->flags, ConstInitializeFlags);
+ if (initArgs->LibraryParameters) {
+ printf("Params: %s\n",initArgs->LibraryParameters);
+ }
case ArgFunctionList:
functionList = (CK_FUNCTION_LIST *)ptr->data;
printf(" Version: %d.%02d\n", VERSION(functionList->version));
@@ -1494,8 +1539,43 @@ printGeneralHelp(void)
return CKR_OK;
}
+static CK_RV
+quitIf(CK_ULONG a, const char *cmp, CK_ULONG b)
+{
+ if (strcmp(cmp, "<") == 0) {
+ return (a < b) ? CKR_QUIT : CKR_OK;
+ } else if (strcmp(cmp, ">") == 0) {
+ return (a > b) ? CKR_QUIT : CKR_OK;
+ } else if (strcmp(cmp, "<=") == 0) {
+ return (a <= b) ? CKR_QUIT : CKR_OK;
+ } else if (strcmp(cmp, ">=") == 0) {
+ return (a >= b) ? CKR_QUIT : CKR_OK;
+ } else if (strcmp(cmp, "=") == 0) {
+ return (a == b) ? CKR_QUIT : CKR_OK;
+ } else if (strcmp(cmp, "!=") == 0) {
+ return (a != b) ? CKR_QUIT : CKR_OK;
+ }
+ printf("Unkown integer comparator: '%s'\n", cmp);
+ return CKR_ARGUMENTS_BAD;
+}
+
+static CK_RV
+quitIfString(const char *a, const char *cmp, const char *b)
+{
+
+ if (strcmp(cmp, "=") == 0) {
+ return (strcmp(a,b) == 0) ? CKR_QUIT : CKR_OK;
+ } else if (strcmp(cmp, "!=") == 0) {
+ return (strcmp(a,b) != 0) ? CKR_QUIT : CKR_OK;
+ }
+ printf("Unkown string comparator: '%s'\n", cmp);
+ return CKR_ARGUMENTS_BAD;
+}
+
CK_RV run(const char *);
CK_RV timeCommand(const char *);
+CK_RV loop(const char *filename, const char *var,
+ CK_ULONG start, CK_ULONG end, CK_ULONG step) ;
/*
* Actually dispatch the function... Bad things happen
@@ -1901,6 +1981,10 @@ do_func(int index, Value **a)
return restore(a[0]->data,a[1]);
case F_Delete:
return DeleteVariable(a[0]->data);
+ case F_Increment:
+ return increment(a[0], *(CK_ULONG *)a[1]->data);
+ case F_Decrement:
+ return decrement(a[0], *(CK_ULONG *)a[1]->data);
case F_List:
return list();
case F_Run:
@@ -1926,6 +2010,9 @@ do_func(int index, Value **a)
case F_NewMechanism:
(void) DeleteVariable(a[0]->data);
return NewMechanism(a[0]->data,*(CK_ULONG *)a[1]->data);
+ case F_NewInitializeArgs:
+ (void) DeleteVariable(a[0]->data);
+ return NewInitializeArgs(a[0]->data,*(CK_ULONG *)a[1]->data,a[2]->data);
case F_System:
value = *(int *)a[0]->data;
if (value & 0x80000000) {
@@ -1934,6 +2021,9 @@ do_func(int index, Value **a)
systemFlags |= value;
}
return CKR_OK;
+ case F_Loop:
+ return loop(a[0]->data,a[1]->data,*(CK_ULONG *)a[2]->data,
+ *(CK_ULONG *)a[3]->data,*(CK_ULONG *)a[4]->data);
case F_Help:
if (a[0]) {
helpIndex = lookup(a[0]->data);
@@ -1944,6 +2034,10 @@ do_func(int index, Value **a)
return CKR_OK;
}
return printGeneralHelp();
+ case F_QuitIfString:
+ return quitIfString(a[0]->data,a[1]->data,a[2]->data);
+ case F_QuitIf:
+ return quitIf(*(CK_ULONG *)a[0]->data,a[1]->data,*(CK_ULONG *)a[2]->data);
case F_Quit:
return CKR_QUIT;
default:
@@ -1992,7 +2086,8 @@ processCommand(const char * buf)
return error;
}
-CK_RV timeCommand(const char *command)
+CK_RV
+timeCommand(const char *command)
{
CK_RV ckrv;
PRIntervalTime startTime = PR_IntervalNow();
@@ -2036,7 +2131,8 @@ process(FILE *inFile,int user)
return ckrv;
}
-CK_RV run(const char *filename)
+CK_RV
+run(const char *filename)
{
FILE *infile;
CK_RV ckrv;
@@ -2054,6 +2150,29 @@ CK_RV run(const char *filename)
return ckrv;
}
+CK_RV
+loop(const char *filename, const char *var,
+ CK_ULONG start, CK_ULONG end, CK_ULONG step)
+{
+ CK_ULONG i = 0;
+ Value *value = 0;
+ CK_RV ckrv;
+
+ for (i=start; i < end; i += step)
+ {
+ value = NewValue(ArgULong, 1);
+ *(CK_ULONG *)value->data = i;
+ DeleteVariable(var);
+ AddVariable(var, &value);
+ ckrv = run(filename);
+ argFree(value);
+ if (ckrv == CKR_QUIT) {
+ break;
+ }
+ }
+ return ckrv;
+}
+
int
main(int argc, char **argv)
{
diff --git a/security/nss/cmd/pk11util/pk11util.h b/security/nss/cmd/pk11util/pk11util.h
index aed07c325..8a2f4d592 100644
--- a/security/nss/cmd/pk11util/pk11util.h
+++ b/security/nss/cmd/pk11util/pk11util.h
@@ -16,6 +16,7 @@ typedef enum {
F_SetVar,
F_SetStringVar,
F_NewArray,
+ F_NewInitializeArgs,
F_NewTemplate,
F_NewMechanism,
F_BuildTemplate,
@@ -23,15 +24,20 @@ typedef enum {
F_Print,
F_SaveVar,
F_RestoreVar,
+ F_Increment,
+ F_Decrement,
F_Delete,
F_List,
F_Run,
F_Load,
F_Unload,
F_System,
+ F_Loop,
F_Time,
F_Help,
F_Quit,
+ F_QuitIf,
+ F_QuitIfString,
} FunctionType;
/*
diff --git a/security/nss/cmd/pk11util/scripts/pkey b/security/nss/cmd/pk11util/scripts/pkey
index 9b6ea0edd..d254f284c 100644
--- a/security/nss/cmd/pk11util/scripts/pkey
+++ b/security/nss/cmd/pk11util/scripts/pkey
Binary files differ