/* * This software may now be redistributed outside the US. * * $Source: /cvs/OpenBSD/src/kerberosIV/krb/Attic/kparse.c,v $ * * $Locker: $ */ /* Copyright (C) 1989 by the Massachusetts Institute of Technology Export of this software from the United States of America is assumed to require a specific license from the United States Government. It is the responsibility of any person or organization contemplating export to obtain such a license before exporting. WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of M.I.T. not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. M.I.T. makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. */ /* * Purpose: * This module was developed to parse the "~/.klogin" files for * Kerberos-authenticated rlogin/rcp/rsh services. However, it is * general purpose and can be used to parse any such parameter file. * * The parameter file should consist of one or more entries, with each * entry on a separate line and consisting of zero or more * "keyword=value" combinations. The keyword is case insensitive, but * the value is not. Any string may be enclosed in quotes, and * c-style "\" literals are supported. A comma may be used to * separate the k/v combinations, and multiple commas are ignored. * Whitespace (blank or tab) may be used freely and is ignored. * * Full error processing is available. When PS_BAD_KEYWORD or * PS_SYNTAX is returned from fGetParameterSet(), the string ErrorMsg * contains a meaningful error message. * * Keywords and their default values are programmed by an external * table. * * Routines: * fGetParameterSet() parse one line of the parameter file * fGetKeywordValue() parse one "keyword=value" combo * fGetToken() parse one token * * " <- emacs fix */ #include "krb_locl.h" #include #ifndef FALSE #define FALSE 0 #define TRUE 1 #endif #define MAXKEY 80 #define MAXVALUE 80 int LineNbr=1; /* current line nbr in parameter file */ char ErrorMsg[80]; /* meaningful only when KV_SYNTAX, PS_SYNTAX, * or PS_BAD_KEYWORD is returned by * fGetKeywordValue or fGetParameterSet */ int fGetParameterSet(fp, parm, parmcount) FILE *fp; parmtable *parm; int parmcount; { int rc,i; char keyword[MAXKEY]; char value[MAXVALUE]; while (TRUE) { rc=fGetKeywordValue(fp,keyword,MAXKEY,value,MAXVALUE); switch (rc) { case KV_EOF: return(PS_EOF); case KV_EOL: return(PS_OKAY); case KV_SYNTAX: return(PS_SYNTAX); case KV_OKAY: /* * got a reasonable keyword/value pair. Search the * parameter table to see if we recognize the keyword; if * not, return an error. If we DO recognize it, make sure * it has not already been given. If not already given, * save the value. */ for (i=0; i= parmcount) { sprintf(ErrorMsg, "unrecognized keyword \"%s\" found", keyword); return(PS_BAD_KEYWORD); } break; default: sprintf(ErrorMsg, "panic: bad return (%d) from fGetToken()",rc); break; } } } /* * Routine: ParmCompare * * Purpose: * ParmCompare checks a specified value for a particular keyword. * fails if keyword not found or keyword found but the value was * different. Like strcmp, ParmCompare returns 0 for a match found, -1 * otherwise */ int ParmCompare(parm, parmcount, keyword, value) parmtable *parm; int parmcount; char *keyword; char *value; { int i; for (i=0; i\n"); exit(1); } if (!(fp=fopen(*++argv,"r"))) { fprintf(stderr,"can\'t open input file \"%s\"\n",filename); exit(1); } filename = *argv; while ((rc=fGetKeywordValue(fp,key,MAXKEY,valu,MAXVALUE))!=KV_EOF){ switch (rc) { case KV_EOL: printf("%s, line %d: nada mas.\n",filename,LineNbr-1); break; case KV_SYNTAX: printf("%s, line %d: syntax error: %s\n", filename,LineNbr,ErrorMsg); while ( ((ch=fGetChar(fp))!=EOF) && (ch!='\n') ); break; case KV_OKAY: printf("%s, line %d: okay, %s=\"%s\"\n", filename,LineNbr,key,valu); break; default: printf("panic: bad return (%d) from fGetKeywordValue\n",rc); break; } } printf("EOF"); fclose(fp); exit(0); } #endif #ifdef PSTEST parmtable kparm[] = { /* keyword, default, found value */ { "user", "", (char *)NULL }, { "realm", "Athena", (char *)NULL }, { "instance", "", (char *)NULL } }; main(argc,argv) int argc; char **argv; { int rc,i,ch; FILE *fp; char *filename; if (argc != 2) { fprintf(stderr,"usage: test \n"); exit(1); } if (!(fp=fopen(*++argv,"r"))) { fprintf(stderr,"can\'t open input file \"%s\"\n",filename); exit(1); } filename = *argv; while ((rc=fGetParameterSet(fp,kparm,PARMCOUNT(kparm))) != PS_EOF) { switch (rc) { case PS_BAD_KEYWORD: printf("%s, line %d: %s\n",filename,LineNbr,ErrorMsg); while ( ((ch=fGetChar(fp))!=EOF) && (ch!='\n') ); break; case PS_SYNTAX: printf("%s, line %d: syntax error: %s\n", filename,LineNbr,ErrorMsg); while ( ((ch=fGetChar(fp))!=EOF) && (ch!='\n') ); break; case PS_OKAY: printf("%s, line %d: valid parameter set found:\n", filename,LineNbr-1); for (i=0; i