[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: kadmin from command line?



dtennant@panasas.com writes:

> Is there a simple way to run a kadmin operation from the command
> line, that forces it to use all the defaults to be used?

Not now, but it sounds like a good idea.  I guess this is mostly
useful for add, right? You can try this patch.

/Johan

Index: util.c
===================================================================
RCS file: /afs/pdc.kth.se/src/packages/kth-krb/SourceRepository/heimdal/kadmin/util.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -w -r1.32 -r1.33
--- util.c	2001/05/14 06:17:20	1.32
+++ util.c	2001/08/10 08:00:26	1.33
@@ -34,7 +34,7 @@
 #include "kadmin_locl.h"
 #include <parse_units.h>
 
-RCSID("$Id: util.c,v 1.32 2001/05/14 06:17:20 assar Exp $");
+RCSID("$Id: util.c,v 1.33 2001/08/10 08:00:26 joda Exp $");
 
 /*
  * util.c - functions for parsing, unparsing, and editing different
@@ -338,42 +338,56 @@
  * allow the user to edit `ent'
  */
 
-int
-edit_entry(kadm5_principal_ent_t ent, int *mask,
+void
+set_defaults(kadm5_principal_ent_t ent, int *mask,
 	   kadm5_principal_ent_t default_ent, int default_mask)
 {
     if (default_ent
 	&& (default_mask & KADM5_MAX_LIFE)
 	&& !(*mask & KADM5_MAX_LIFE))
 	ent->max_life = default_ent->max_life;
-    edit_deltat ("Max ticket life", &ent->max_life, mask,
-		 KADM5_MAX_LIFE);
 
     if (default_ent
 	&& (default_mask & KADM5_MAX_RLIFE)
 	&& !(*mask & KADM5_MAX_RLIFE))
 	ent->max_renewable_life = default_ent->max_renewable_life;
-    edit_deltat ("Max renewable life", &ent->max_renewable_life, mask,
-		 KADM5_MAX_RLIFE);
 
     if (default_ent
 	&& (default_mask & KADM5_PRINC_EXPIRE_TIME)
 	&& !(*mask & KADM5_PRINC_EXPIRE_TIME))
 	ent->princ_expire_time = default_ent->princ_expire_time;
-    edit_timet ("Principal expiration time", &ent->princ_expire_time, mask,
-	       KADM5_PRINC_EXPIRE_TIME);
 
     if (default_ent
 	&& (default_mask & KADM5_PW_EXPIRATION)
 	&& !(*mask & KADM5_PW_EXPIRATION))
 	ent->pw_expiration = default_ent->pw_expiration;
-    edit_timet ("Password expiration time", &ent->pw_expiration, mask,
-	       KADM5_PW_EXPIRATION);
 
     if (default_ent
 	&& (default_mask & KADM5_ATTRIBUTES)
 	&& !(*mask & KADM5_ATTRIBUTES))
 	ent->attributes = default_ent->attributes & ~KRB5_KDB_DISALLOW_ALL_TIX;
+    return 0;
+}
+
+int
+edit_entry(kadm5_principal_ent_t ent, int *mask,
+	   kadm5_principal_ent_t default_ent, int default_mask)
+{
+
+    set_defaults(ent, mask, default_ent, default_mask);
+
+    edit_deltat ("Max ticket life", &ent->max_life, mask,
+		 KADM5_MAX_LIFE);
+
+    edit_deltat ("Max renewable life", &ent->max_renewable_life, mask,
+		 KADM5_MAX_RLIFE);
+
+    edit_timet ("Principal expiration time", &ent->princ_expire_time, mask,
+	       KADM5_PRINC_EXPIRE_TIME);
+
+    edit_timet ("Password expiration time", &ent->pw_expiration, mask,
+	       KADM5_PW_EXPIRATION);
+
     edit_attributes ("Attributes", &ent->attributes, mask,
 		     KADM5_ATTRIBUTES);
     return 0;
Index: ank.c
===================================================================
RCS file: /afs/pdc.kth.se/src/packages/kth-krb/SourceRepository/heimdal/kadmin/ank.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -w -r1.21 -r1.22
--- ank.c	2000/09/10 19:16:39	1.21
+++ ank.c	2001/08/10 08:08:22	1.22
@@ -33,7 +33,7 @@
 
 #include "kadmin_locl.h"
 
-RCSID("$Id: ank.c,v 1.21 2000/09/10 19:16:39 joda Exp $");
+RCSID("$Id: ank.c,v 1.22 2001/08/10 08:08:22 joda Exp $");
 
 /*
  * fetch the default principal corresponding to `princ'
@@ -67,6 +67,7 @@
 add_one_principal (const char *name,
 		   int rand_key,
 		   int rand_password,
+		   int use_defaults, 
 		   char *password,
 		   krb5_key_data *key_data,
 		   const char *max_ticket_life,
@@ -108,6 +109,9 @@
 	    KADM5_PRINC_EXPIRE_TIME | KADM5_PW_EXPIRATION;
     }
 
+    if(use_defaults) 
+	set_defaults(&princ, &mask, default_ent, default_mask);
+    else
     edit_entry(&princ, &mask, default_ent, default_mask);
     if(rand_key || key_data) {
 	princ.attributes |= KRB5_KDB_DISALLOW_ALL_TIX;
@@ -200,10 +204,11 @@
       "max renewable lifetime", "lifetime" },
     { "attributes",	0,	arg_string,	NULL, "principal attributes",
       "attributes"},
-    { "expiration-time",0,	arg_string,	NULL, "Expiration time",
+    { "expiration-time",0,	arg_string,	NULL, "expiration time",
       "time"},
     { "pw-expiration-time", 0,  arg_string,	NULL,
-      "Password expiration time", "time"}
+      "password expiration time", "time"},
+    { "use-defaults",	0,	arg_flag,	NULL, "use default values" }
 };
 
 static int num_args = sizeof(args) / sizeof(args[0]);
@@ -232,6 +237,7 @@
     char *attributes		= NULL;
     char *expiration		= NULL;
     char *pw_expiration		= NULL;
+    int use_defaults = 0;
     int i;
     int num;
     krb5_key_data key_data[3];
@@ -246,6 +252,7 @@
     args[6].value = &attributes;
     args[7].value = &expiration;
     args[8].value = &pw_expiration;
+    args[9].value = &use_defaults;
     
     if(getarg(args, num_args, argc, argv, &optind)) {
 	usage ();
@@ -284,6 +291,7 @@
 
     for (i = optind; i < argc; ++i) {
 	ret = add_one_principal (argv[i], random_key, random_password,
+				 use_defaults, 
 				 password,
 				 kdp,
 				 max_ticket_life,
Index: kadmin_locl.h
===================================================================
RCS file: /afs/pdc.kth.se/src/packages/kth-krb/SourceRepository/heimdal/kadmin/kadmin_locl.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -w -r1.36 -r1.37
--- kadmin_locl.h	2001/05/07 05:32:04	1.36
+++ kadmin_locl.h	2001/08/10 08:00:47	1.37
@@ -32,7 +32,7 @@
  */
 
 /* 
- * $Id: kadmin_locl.h,v 1.36 2001/05/07 05:32:04 assar Exp $
+ * $Id: kadmin_locl.h,v 1.37 2001/08/10 08:00:47 joda Exp $
  */
 
 #ifndef __ADMIN_LOCL_H__
@@ -145,6 +145,8 @@
 
 int edit_entry(kadm5_principal_ent_t ent, int *mask,
 	       kadm5_principal_ent_t default_ent, int default_mask);
+void set_defaults(kadm5_principal_ent_t ent, int *mask,
+		  kadm5_principal_ent_t default_ent, int default_mask);
 int set_entry(krb5_context context,
 	      kadm5_principal_ent_t ent,
 	      int *mask,