home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / amd / part02 / info_hes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-10  |  2.5 KB  |  99 lines

  1. /*
  2.  * $Id: info_hes.c,v 5.1.1.1 89/11/28 17:46:59 jsp Exp Locker: jsp $
  3.  *
  4.  * Copyright (c) 1989 Jan-Simon Pendry
  5.  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
  6.  * Copyright (c) 1989 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * This code is derived from software contributed to Berkeley by
  10.  * Jan-Simon Pendry at Imperial College, London.
  11.  *
  12.  * Redistribution and use in source and binary forms are permitted
  13.  * provided that the above copyright notice and this paragraph are
  14.  * duplicated in all such forms and that any documentation,
  15.  * advertising materials, and other materials related to such
  16.  * distribution and use acknowledge that the software was developed
  17.  * by Imperial College of Science, Technology and Medicine, London, UK.
  18.  * The names of the College and University may not be used to endorse
  19.  * or promote products derived from this software without specific
  20.  * prior written permission.
  21.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  22.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  23.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  24.  *
  25.  *    %W% (Berkeley) %G%
  26.  */
  27.  
  28. /*
  29.  * Get info from Hesiod
  30.  */
  31.  
  32. #include "am.h"
  33.  
  34. #ifdef HAS_HESIOD_MAPS
  35. #include <hesiod.h>
  36.  
  37. #define    HES_PREFIX    "hesiod."
  38. #define    HES_PREFLEN    7
  39.  
  40. /*
  41.  * No way to probe the server - check the map name begins with "hesiod."
  42.  */
  43. hesiod_init(map)
  44. char *map;
  45. {
  46.     return strncmp(map, HES_PREFIX, HES_PREFLEN) == 0 ? 0 : ENOENT;
  47. }
  48.  
  49.  
  50. /*
  51.  * Do a Hesiod nameserver call.
  52.  * Modify time is ignored by Hesiod - XXX
  53.  */
  54. int hesiod_search(m, map, key, pval, tp)
  55. mnt_map *m;
  56. char *map;
  57. char *key;
  58. char **pval;
  59. time_t *tp;
  60. {
  61.     int error;
  62.     char hes_map[MAXPATHLEN];
  63.     char **rvec;
  64.     /*
  65.      * Make Hesiod name.  Skip past the "hesiod."
  66.      * at the start of the map name and append
  67.      * ".automount".  The net effect is that a lookup
  68.      * of /defaults in hesiod.home will result in a
  69.      * call to hes_resolve("/defaults", "home.automount");
  70.      */
  71.     sprintf(hes_map, "%s%s", map + HES_PREFLEN, ".automount");
  72.     /*
  73.      * Call the resolver
  74.      */
  75.     rvec = hes_resolve(key, hes_map);
  76.     /*
  77.      * If a reply was forthcoming then return
  78.      * it (and free subsequent replies)
  79.      */
  80.     if (rvec && *rvec) {
  81.         *pval = *rvec;
  82.         while (*++rvec)
  83.             free(*rvec);
  84.         return 0;
  85.     }
  86.  
  87.     /*
  88.      * Otherwise reflect the hesiod error into a Un*x error
  89.      */
  90.     switch (hes_error()) {
  91.     case HES_ER_NOTFOUND:    error = ENOENT; break;
  92.     case HES_ER_CONFIG:    error = EIO; break;
  93.     case HES_ER_NET:    error = ETIMEDOUT; break;
  94.     default:        error = EINVAL; break;
  95.     }
  96.     return error;
  97. }
  98. #endif
  99.