home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / radius_2.zip / attrprint.c < prev    next >
C/C++ Source or Header  |  1996-05-15  |  3KB  |  105 lines

  1. /*
  2.  *
  3.  *    RADIUS
  4.  *    Remote Authentication Dial In User Service
  5.  *
  6.  *
  7.  *    Livingston Enterprises, Inc.
  8.  *    6920 Koll Center Parkway
  9.  *    Pleasanton, CA   94566
  10.  *
  11.  *    Copyright 1992 Livingston Enterprises, Inc.
  12.  *
  13.  *    Permission to use, copy, modify, and distribute this software for any
  14.  *    purpose and without fee is hereby granted, provided that this
  15.  *    copyright and permission notice appear on all copies and supporting
  16.  *    documentation, the name of Livingston Enterprises, Inc. not be used
  17.  *    in advertising or publicity pertaining to distribution of the
  18.  *    program without specific prior permission, and notice be given
  19.  *    in supporting documentation that copying and distribution is by
  20.  *    permission of Livingston Enterprises, Inc.   
  21.  *
  22.  *    Livingston Enterprises, Inc. makes no representations about
  23.  *    the suitability of this software for any purpose.  It is
  24.  *    provided "as is" without express or implied warranty.
  25.  *
  26.  */
  27.  
  28. static char sccsid[] =
  29. "@(#)@(#)attrprint.c    1.3 Copyright 1992 Livingston Enterprises Inc";
  30.  
  31. #include    <sys/types.h>
  32. #include    <sys/socket.h>
  33. #include    <sys/time.h>
  34. #include    <netinet/in.h>
  35.  
  36. #include    <stdio.h>
  37. #include    <netdb.h>
  38. #include    <pwd.h>
  39. #include    <time.h>
  40. #include    <ctype.h>
  41.  
  42. #include    "radius.h"
  43.  
  44. /*************************************************************************
  45.  *
  46.  *    Function: fprint_attr_val
  47.  *
  48.  *    Purpose: Write a printable version of the attribute-value
  49.  *         pair to the supplied File.
  50.  *
  51.  *************************************************************************/
  52. void
  53. fprint_attr_val(fd, pair)
  54. FILE        *fd;
  55. VALUE_PAIR    *pair;
  56. {
  57.     DICT_VALUE    *dict_valget();
  58.     DICT_VALUE    *dval;
  59.     char        buffer[32];
  60.     u_char        *ptr;
  61.  
  62.     switch(pair->type) {
  63.  
  64.     case PW_TYPE_STRING:
  65.         fprintf(fd, "%s = \"", pair->name);
  66.         ptr = (u_char *)pair->strvalue;
  67.         while(*ptr != '\0') {
  68.             if(!(isprint(*ptr))) {
  69.                 fprintf(fd, "\\%03o", *ptr);
  70.             }
  71.             else {
  72.                 fputc(*ptr, fd);
  73.             }
  74.             ptr++;
  75.         }
  76.         fputc('"', fd);
  77.         break;
  78.             
  79.     case PW_TYPE_INTEGER:
  80.         dval = dict_valget(pair->lvalue, pair->name);
  81.         if(dval != (DICT_VALUE *)NULL) {
  82.             fprintf(fd, "%s = %s", pair->name, dval->name);
  83.         }
  84.         else {
  85.             fprintf(fd, "%s = %ld", pair->name, pair->lvalue);
  86.         }
  87.         break;
  88.  
  89.     case PW_TYPE_IPADDR:
  90.         ipaddr2str(buffer, pair->lvalue);
  91.         fprintf(fd, "%s = %s", pair->name, buffer);
  92.         break;
  93.  
  94.     case PW_TYPE_DATE:
  95.         strftime(buffer, sizeof(buffer), "%b %e %Y",
  96.                     gmtime((time_t *)&pair->lvalue));
  97.         fprintf(fd, "%s = \"%s\"", pair->name, buffer);
  98.         break;
  99.  
  100.     default:
  101.         fprintf(fd, "Unknown type %d", pair->type);
  102.         break;
  103.     }
  104. }
  105.