4 * Copyright (c) 2009 The NetBSD Foundation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote
16 * products derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 /* Code contributed by Greywolf <greywolf@starwolf.com>
33 * 28 August 2003. All rights released to The NetBSD Foundation.
36 #include <sys/cdefs.h>
49 #include "ypalias_init.h"
51 #ifndef _PATH_YPNICKNAMES
52 #define _PATH_YPNICKNAMES "/var/yp/nicknames"
55 const struct ypalias def_ypaliases
[] = {
56 { "passwd", "passwd.byname" },
57 { "group", "group.byname" },
58 { "networks", "networks.byaddr" },
59 { "hosts", "hosts.byaddr" },
60 { "protocols", "protocols.bynumber" },
61 { "services", "services.byname" },
62 { "aliases", "mail.aliases" },
63 { "ethers", "ethers.byname" },
67 const struct ypalias
*
72 struct ypalias
*ypa
, *nypa
;
74 size_t i
, len
, lineno
;
76 if ((fp
= fopen(_PATH_YPNICKNAMES
, "r")) == NULL
)
77 return &def_ypaliases
[0];
79 if ((ypa
= calloc(sizeof(*ypa
), nypalias
)) == NULL
)
83 for (i
= 0; (line
= fparseln(fp
, &len
, &lineno
, NULL
,
84 FPARSELN_UNESCALL
));) {
86 /* Ignore malformed lines */
87 if ((ypa
[i
].alias
= strsep(&line
, " \t\n")) == NULL
||
88 (ypa
[i
].name
= strsep(&line
, " \t\n")) == NULL
||
90 warnx("%s, %zu: syntax error, ignored",
91 _PATH_YPNICKNAMES
, lineno
);
97 nypa
= realloc(ypa
, sizeof(*ypa
) * nypalias
);
103 ypa
[i
].alias
= ypa
[i
].name
= NULL
;
107 if ((nypa
= realloc(ypa
, sizeof(*ypa
) * i
)) != NULL
)
110 warn("Cannot alllocate alias space, returning default list");
113 free(__UNCONST(ypa
[--i
].alias
));
118 return def_ypaliases
;