home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / kerberosIV / krb / get_krbrlm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-29  |  1.7 KB  |  73 lines

  1. /*
  2.  * $Source: /usr/src/kerberosIV/krb/RCS/get_krbrlm.c,v $
  3.  * $Author: kfall $
  4.  *
  5.  * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
  6.  * of Technology.
  7.  *
  8.  * For copying and distribution information, please see the file
  9.  * <mit-copyright.h>.
  10.  */
  11.  
  12. #ifndef lint
  13. static char *rcsid_get_krbrlm_c =
  14. "$Header: /usr/src/kerberosIV/krb/RCS/get_krbrlm.c,v 4.10 91/03/29 15:10:53 kfall Exp Locker: kfall $";
  15. #endif /* lint */
  16.  
  17. #include <mit-copyright.h>
  18. #include <stdio.h>
  19. #include <des.h>
  20. #include <krb.h>
  21. #include <strings.h>
  22.  
  23. /*
  24.  * krb_get_lrealm takes a pointer to a string, and a number, n.  It fills
  25.  * in the string, r, with the name of the nth realm specified on the
  26.  * first line of the kerberos config file (KRB_CONF, defined in "krb.h").
  27.  * It returns 0 (KSUCCESS) on success, and KFAILURE on failure.  If the
  28.  * config file does not exist, and if n=1, a successful return will occur
  29.  * with r = KRB_REALM (also defined in "krb.h").
  30.  *
  31.  * NOTE: for archaic & compatibility reasons, this routine will only return
  32.  * valid results when n = 1.
  33.  *
  34.  * For the format of the KRB_CONF file, see comments describing the routine
  35.  * krb_get_krbhst().
  36.  */
  37.  
  38. krb_get_lrealm(r,n)
  39.     char *r;
  40.     int n;
  41. {
  42.     FILE *cnffile, *fopen();
  43.  
  44.     
  45.     if ((cnffile = fopen(KRB_CONF, "r")) == (FILE *) NULL)
  46.         return(KFAILURE);
  47.  
  48. #ifdef notdef
  49.  
  50.     dont want this -- kfall
  51.  
  52.     if (n > 1)
  53.     return(KFAILURE);  /* Temporary restriction */
  54.  
  55.     if ((cnffile = fopen(KRB_CONF, "r")) == NULL) {
  56.     if (n == 1) {
  57.         (void) strcpy(r, KRB_REALM);
  58.         return(KSUCCESS);
  59.     }
  60.     else
  61.         return(KFAILURE);
  62.     }
  63.  
  64. #endif
  65.  
  66.     if (fscanf(cnffile,"%s",r) != 1) {
  67.         (void) fclose(cnffile);
  68.         return(KFAILURE);
  69.     }
  70.     (void) fclose(cnffile);
  71.     return(KSUCCESS);
  72. }
  73.