MFC r1.8:
[dragonfly.git] / usr.bin / chpass / pw_yp.h
blobd99f0ee66d1e48481c632688eb4245ea4615a2f6
1 /*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
32 * NIS interface routines for chpass
34 * Written by Bill Paul <wpaul@ctr.columbia.edu>
35 * Center for Telecommunications Research
36 * Columbia University, New York City
38 * $FreeBSD: src/usr.bin/chpass/pw_yp.h,v 1.7.2.1 2002/02/15 00:46:56 des Exp $
39 * $DragonFly: src/usr.bin/chpass/pw_yp.h,v 1.2 2003/06/17 04:29:25 dillon Exp $
42 #ifdef YP
43 #include <sys/types.h>
44 #include <rpc/rpc.h>
45 #include <rpc/auth.h>
46 #include <rpc/auth_unix.h>
47 /* Four possible return codes from use_yp() */
48 #define USER_UNKNOWN 0
49 #define USER_YP_ONLY 1
50 #define USER_LOCAL_ONLY 2
51 #define USER_YP_AND_LOCAL 3
53 extern int force_old;
54 extern int _use_yp;
55 extern int suser_override;
56 extern struct passwd local_password;
57 extern struct passwd yp_password;
58 extern void copy_yp_pass(char *, int, int);
59 extern char *yp_domain;
60 extern char *yp_server;
61 extern void yp_submit(struct passwd *);
62 extern int use_yp(char *, uid_t, int);
63 extern char *get_yp_master(int);
64 extern int yp_in_pw_file;
67 * Yucky.
69 #define GETPWUID(X) \
70 _use_yp = use_yp(NULL, X, 1); \
72 if (_use_yp == USER_UNKNOWN) { \
73 errx(1, "unknown user: uid %u", X); \
74 } \
76 if (_use_yp == USER_YP_ONLY) { \
77 if (!force_local) { \
78 _use_yp = 1; \
79 pw = (struct passwd *)&yp_password; \
80 } else \
81 errx(1, "unknown local user: uid %u", X); \
82 } else if (_use_yp == USER_LOCAL_ONLY) { \
83 if (!force_yp) { \
84 _use_yp = 0; \
85 pw = (struct passwd *)&local_password; \
86 } else \
87 errx(1, "unknown NIS user: uid %u", X); \
88 } else if (_use_yp == USER_YP_AND_LOCAL) { \
89 if (!force_local && (force_yp || yp_in_pw_file)) { \
90 _use_yp = 1; \
91 pw = (struct passwd *)&yp_password; \
92 } else { \
93 _use_yp = 0; \
94 pw = (struct passwd *)&local_password; \
95 } \
98 #define GETPWNAM(X) \
99 _use_yp = use_yp(X, 0, 0); \
101 if (_use_yp == USER_UNKNOWN) { \
102 errx(1, "unknown user: %s", X); \
105 if (_use_yp == USER_YP_ONLY) { \
106 if (!force_local) { \
107 _use_yp = 1; \
108 pw = (struct passwd *)&yp_password; \
109 } else \
110 errx(1, "unknown local user: %s.", X); \
111 } else if (_use_yp == USER_LOCAL_ONLY) { \
112 if (!force_yp) { \
113 _use_yp = 0; \
114 pw = (struct passwd *)&local_password; \
115 } else \
116 errx(1, "unknown NIS user: %s.", X); \
117 } else if (_use_yp == USER_YP_AND_LOCAL) { \
118 if (!force_local && (force_yp || yp_in_pw_file)) { \
119 _use_yp = 1; \
120 pw = (struct passwd *)&yp_password; \
121 } else { \
122 _use_yp = 0; \
123 pw = (struct passwd *)&local_password; \
127 #endif /* YP */