1 /* Copyright 1996 by the Massachusetts Institute of Technology.
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
16 /* This file is part of the Hesiod library. It implements
17 * backward-compatibility interfaces.
20 static char rcsid[] = "$Id: hescompat.c,v 1.1.2.1 1996/12/16 08:37:45 ghudson Exp $";
27 static int inited = 0;
29 static char *bindname, **list;
30 static struct passwd *pw;
31 static struct servent *serv;
32 static struct hesiod_postoffice *po;
33 static struct hes_postoffice compatpo;
34 static int errval = HES_ER_UNINIT;
36 static int init_context(void);
37 static void translate_errors(void);
45 char *hes_to_bind(const char *name, const char *type)
47 if (init_context() < 0)
51 bindname = hesiod_to_bind(context, name, type);
57 char **hes_resolve(const char *name, const char *type)
59 if (init_context() < 0)
62 /* In the old Hesiod interface, the caller was responsible for freeing
63 * the returned strings but not the vector of strings itself.
68 list = hesiod_resolve(context, name, type);
79 struct passwd *hes_getpwnam(const char *name)
81 if (init_context() < 0)
84 hesiod_free_passwd(context, pw);
85 pw = hesiod_getpwnam(context, name);
91 struct passwd *hes_getpwuid(uid_t uid)
93 if (init_context() < 0)
96 hesiod_free_passwd(context, pw);
97 pw = hesiod_getpwuid(context, uid);
103 struct servent *hes_getservbyname(const char *name, const char *proto)
105 if (init_context() < 0)
108 hesiod_free_servent(context, serv);
109 serv = hesiod_getservbyname(context, name, proto);
115 struct hes_postoffice *hes_getmailhost(const char *name)
117 if (init_context() < 0)
120 hesiod_free_postoffice(context, po);
121 po = hesiod_getmailhost(context, name);
127 compatpo.po_type = po->hesiod_po_type;
128 compatpo.po_host = po->hesiod_po_host;
129 compatpo.po_name = po->hesiod_po_name;
133 static int init_context()
138 if (hesiod_init(&context) < 0)
140 errval = HES_ER_CONFIG;
148 static void translate_errors()
153 errval = HES_ER_NOTFOUND;
161 /* Not a good match, but the best we can do. */
162 errval = HES_ER_CONFIG;