home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / protocol / kerberos / 977 < prev    next >
Encoding:
Text File  |  1992-12-24  |  8.7 KB  |  305 lines

  1. Newsgroups: comp.protocols.kerberos
  2. Path: sparky!uunet!stanford.edu!aktis.com!bjaspan
  3. From: bjaspan@aktis.com ("Barry Jaspan")
  4. Subject: V5 kinit patch: "ksrvtgt" functionality
  5. Message-ID: <9212242131.AA01740@suan-la-chow-show.aktis.com>
  6. Sender: news@shelby.stanford.edu (USENET News System)
  7. Organization: Internet-USENET Gateway at Stanford University
  8. Date: Thu, 24 Dec 1992 21:31:58 GMT
  9. Lines: 294
  10.  
  11.  
  12. The V4 program ksrvtgt always had the frustrating property of being
  13. less flexible than kinit, even though it performed essentially the
  14. same function (namely, obtaining a tgt for a specified principal,
  15. using a key from a srvtab instead of a password provided by the user).
  16.  
  17. Since the current V5 distribution does not appear to contain a
  18. ksrvtgt, I decided to prevent the problem from recurring by extending
  19. kinit to provide "ksrvtgt functionality."  I have added two command
  20. line options:
  21.  
  22. -k -- read the principal's key from the keytab instead of reading it
  23. from the keyboard
  24.  
  25. -t keytab -- use the keytab <keytab> instead of the default keytab.
  26.  
  27. All other options operate normally.  If no principal name is
  28. specified, the default host principal (host/canonical_host_name@REALM)
  29. is used.
  30.  
  31. Barry Jaspan, bjaspan@aktis.com
  32. Aktis, Inc.
  33.  
  34. ===================================================================
  35. RCS file: RCS/kinit.c,v
  36. retrieving revision 5.23
  37. diff -c -r5.23 kinit.c
  38. *** 5.23    1992/09/30 14:09:54
  39. --- kinit.c    1992/12/24 21:16:22
  40. ***************
  41. *** 68,73 ****
  42. --- 68,74 ----
  43.   {
  44.       krb5_ccache ccache = NULL;
  45.       char *cache_name = NULL;        /* -f option */
  46. +     char *keytab_name = NULL;        /* -t option */
  47.       long lifetime = KRB5_DEFAULT_LIFE;    /* -l option */
  48.       long rlife = 0;
  49.       int options = KRB5_DEFAULT_OPTIONS;
  50. ***************
  51. *** 79,84 ****
  52. --- 80,88 ----
  53.       krb5_principal server;
  54.       krb5_creds my_creds;
  55.       krb5_timestamp now;
  56. +     int use_keytab = 0;            /* -k option */
  57. +     krb5_keytab keytab = NULL;
  58. +     krb5_keytab_entry kt_ent;
  59.       struct passwd *pw = 0;
  60.       int pwsize;
  61.       char password[255], *client_name, prompt[255];
  62. ***************
  63. *** 88,94 ****
  64.       if (strrchr(argv[0], '/'))
  65.       argv[0] = strrchr(argv[0], '/')+1;
  66.   
  67. !     while ((option = getopt(argc, argv, "r:fpl:c:")) != EOF) {
  68.       switch (option) {
  69.       case 'r':
  70.           options |= KDC_OPT_RENEWABLE;
  71. --- 92,98 ----
  72.       if (strrchr(argv[0], '/'))
  73.       argv[0] = strrchr(argv[0], '/')+1;
  74.   
  75. !     while ((option = getopt(argc, argv, "r:fpl:c:kt:")) != EOF) {
  76.       switch (option) {
  77.       case 'r':
  78.           options |= KDC_OPT_RENEWABLE;
  79. ***************
  80. *** 104,110 ****
  81.       case 'f':
  82.           options |= KDC_OPT_FORWARDABLE;
  83.           break;
  84. !     case 'l':
  85.           code = krb5_parse_lifetime(optarg, &lifetime);
  86.           if (code != 0 || lifetime == 0) {
  87.           fprintf(stderr, "Bad lifetime value (%s hours?)\n", optarg);
  88. --- 108,132 ----
  89.       case 'f':
  90.           options |= KDC_OPT_FORWARDABLE;
  91.           break;
  92. !        case 'k':
  93. !         use_keytab = 1;
  94. !         break;
  95. !        case 't':
  96. !         if (keytab == NULL) {
  97. !          keytab_name = optarg;
  98. !          code = krb5_kt_resolve(keytab_name, &keytab);
  99. !          if (code != 0) {
  100. !               com_err(argv[0], code, "resolving keytab %s",
  101. !                   keytab_name);
  102. !          errflg++;
  103. !          }
  104. !         } else {
  105. !          fprintf(stderr, "Only one -t option allowed.\n");
  106. !          errflg++;
  107. !         }
  108. !         break;
  109. !        case 'l':
  110.           code = krb5_parse_lifetime(optarg, &lifetime);
  111.           if (code != 0 || lifetime == 0) {
  112.           fprintf(stderr, "Bad lifetime value (%s hours?)\n", optarg);
  113. ***************
  114. *** 117,123 ****
  115.           
  116.           code = krb5_cc_resolve (cache_name, &ccache);
  117.           if (code != 0) {
  118. !             com_err (argv[0], code, "resolving %s", cache_name);
  119.               errflg++;
  120.           }
  121.           } else {
  122. --- 139,146 ----
  123.           
  124.           code = krb5_cc_resolve (cache_name, &ccache);
  125.           if (code != 0) {
  126. !             com_err (argv[0], code, "resolving ccache %s",
  127. !                  cache_name);
  128.               errflg++;
  129.           }
  130.           } else {
  131. ***************
  132. *** 133,173 ****
  133.       }
  134.   
  135.       if (errflg) {
  136. !     fprintf(stderr, "Usage: %s [ -r time ] [ -puf ] [ -l lifetime ] [ -c cachename ] [principal]\n", argv[0]);
  137.       exit(2);
  138.       }
  139.   
  140.       if (ccache == NULL) {
  141. !     if (code = krb5_cc_default(&ccache)) {
  142. !         com_err(argv[0], code, "while getting default ccache");
  143. !         exit(1);
  144. !     }
  145.       }
  146. !     
  147.       if (optind != argc-1) {       /* No principal name specified */
  148. !     /* Get default principal from cache if one exists */
  149. !     code = krb5_cc_get_principal(ccache, &me);
  150. !     /* Else search passwd file for client */
  151. !     if (code) {
  152. !         pw = getpwuid((int) getuid());
  153. !         if (pw) {
  154. !         if (code = krb5_parse_name (pw->pw_name, &me)) {
  155. !             com_err (argv[0], code, "when parsing name %s", pw->pw_name);
  156. !             exit(1);
  157. !         }
  158. !         } 
  159. !         else {
  160. !         fprintf(stderr, 
  161.               "Unable to identify user from password file\n");
  162. !         exit(1);
  163. !         }
  164. !     }
  165.       }
  166. -     else /* Use specified name */
  167. -       if (code = krb5_parse_name (argv[optind], &me)) {
  168. -       com_err (argv[0], code, "when parsing name %s",argv[optind]);
  169. -       exit(1);
  170. -       }
  171.       
  172.       if (code = krb5_unparse_name(me, &client_name)) {
  173.       com_err (argv[0], code, "when unparsing name");
  174. --- 156,206 ----
  175.       }
  176.   
  177.       if (errflg) {
  178. !     fprintf(stderr, "Usage: %s [-r time] [-puf] [-l lifetime] [-c cachename] [-k] [-t keytab] [principal]\n", argv[0]);
  179.       exit(2);
  180.       }
  181.   
  182.       if (ccache == NULL) {
  183. !      if (code = krb5_cc_default(&ccache)) {
  184. !           com_err(argv[0], code, "while getting default ccache");
  185. !           exit(1);
  186. !      }
  187.       }
  188.       if (optind != argc-1) {       /* No principal name specified */
  189. !      if (use_keytab) {
  190. !           /* Use the default host/service name */
  191. !           code = krb5_sname_to_principal(NULL, NULL,
  192. !                          KRB5_NT_SRV_HST, &me);
  193. !           if (code) {
  194. !            com_err(argv[0], code,
  195. !                "when creating default server principal name");
  196. !            exit(1);
  197. !           }
  198. !      } else {
  199. !           /* Get default principal from cache if one exists */
  200. !           code = krb5_cc_get_principal(ccache, &me);
  201. !           if (code) {
  202. !            /* Else search passwd file for client */
  203. !            pw = getpwuid((int) getuid());
  204. !            if (pw) {
  205. !             if (code = krb5_parse_name (pw->pw_name, &me)) {
  206. !                  com_err (argv[0], code, "when parsing name %s",
  207. !                       pw->pw_name);
  208. !                  exit(1);
  209. !             }
  210. !            } else {
  211. !             fprintf(stderr, 
  212.               "Unable to identify user from password file\n");
  213. !             exit(1);
  214. !            }
  215. !           }
  216. !      }
  217. !     } /* Use specified name */     
  218. !     else if (code = krb5_parse_name (argv[optind], &me)) {
  219. !      com_err (argv[0], code, "when parsing name %s",argv[optind]);
  220. !      exit(1);
  221.       }
  222.       
  223.       if (code = krb5_unparse_name(me, &client_name)) {
  224.       com_err (argv[0], code, "when unparsing name");
  225. ***************
  226. *** 215,241 ****
  227.       } else
  228.       my_creds.times.renew_till = 0;
  229.   
  230. !     (void) sprintf(prompt,"Password for %s: ", (char *) client_name);
  231.   
  232. !     pwsize = sizeof(password);
  233.   
  234. !     code = krb5_read_password(prompt, 0, password, &pwsize);
  235. !     if (code || pwsize == 0) {
  236. !     fprintf(stderr, "Error while reading password for '%s'\n",
  237. !         client_name);
  238. !     memset(password, 0, sizeof(password));
  239. !     krb5_free_addresses(my_addresses);
  240. !     exit(1);
  241.       }
  242. !     code = krb5_get_in_tkt_with_password(options, my_addresses,
  243. !                      KRB5_PADATA_ENC_TIMESTAMP,
  244. !                      ETYPE_DES_CBC_CRC,
  245. !                      KEYTYPE_DES,
  246. !                      password,
  247. !                      ccache,
  248. !                      &my_creds, 0);
  249. !     memset(password, 0, sizeof(password));
  250.       krb5_free_principal(server);
  251.       krb5_free_addresses(my_addresses);
  252.       
  253. --- 248,295 ----
  254.       } else
  255.       my_creds.times.renew_till = 0;
  256.   
  257. !     if (!use_keytab) {
  258. !      (void) sprintf(prompt,"Password for %s: ", (char *) client_name);
  259.   
  260. !      pwsize = sizeof(password);
  261.   
  262. !      code = krb5_read_password(prompt, 0, password, &pwsize);
  263. !      if (code || pwsize == 0) {
  264. !           fprintf(stderr, "Error while reading password for '%s'\n",
  265. !               client_name);
  266. !           memset(password, 0, sizeof(password));
  267. !           krb5_free_addresses(my_addresses);
  268. !           exit(1);
  269. !      }
  270. !      code = krb5_get_in_tkt_with_password(options, my_addresses,
  271. !                           KRB5_PADATA_ENC_TIMESTAMP,
  272. !                           ETYPE_DES_CBC_CRC,
  273. !                           KEYTYPE_DES,
  274. !                           password,
  275. !                           ccache,
  276. !                           &my_creds, 0);
  277. !      memset(password, 0, sizeof(password));
  278. !     } else {
  279. !      if (keytab != NULL) {
  280. !           code = krb5_kt_get_entry(keytab, my_creds.client, 0,
  281. !                        &kt_ent);
  282. !           if (code) {
  283. !            com_err(argv[0], code, "reading keytab entry %s",
  284. !                client_name);
  285. !            exit(1);
  286. !           }
  287. !      }
  288. !            
  289. !      code = krb5_get_in_tkt_with_skey(options, my_addresses,
  290. !                       KRB5_PADATA_ENC_TIMESTAMP,
  291. !                       ETYPE_DES_CBC_CRC,
  292. !                       keytab ? &kt_ent.key : NULL,
  293. !                       ccache, &my_creds, 0);
  294. !      if (keytab != NULL)
  295. !           krb5_kt_free_entry(&kt_ent);
  296.       }
  297. !     
  298.       krb5_free_principal(server);
  299.       krb5_free_addresses(my_addresses);
  300.       
  301.