]> git.cameronkatri.com Git - pw-darwin.git/blob - chpass/pw_yp.h
Free a malloc'ed variable before exiting. Compute line number when parsing
[pw-darwin.git] / chpass / pw_yp.h
1 /*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
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.
19 *
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.
31 *
32 * NIS interface routines for chpass
33 *
34 * Written by Bill Paul <wpaul@ctr.columbia.edu>
35 * Center for Telecommunications Research
36 * Columbia University, New York City
37 *
38 * $Id$
39 */
40
41 #ifdef YP
42 #include <sys/types.h>
43 #include <rpc/rpc.h>
44 #include <rpc/auth.h>
45 #include <rpc/auth_unix.h>
46 /* Four possible return codes from use_yp() */
47 #define USER_UNKNOWN 0
48 #define USER_YP_ONLY 1
49 #define USER_LOCAL_ONLY 2
50 #define USER_YP_AND_LOCAL 3
51
52 extern int force_old;
53 extern int _use_yp;
54 extern int suser_override;
55 extern struct passwd local_password;
56 extern struct passwd yp_password;
57 extern void copy_yp_pass __P(( char *, int, int ));
58 extern char *yp_domain;
59 extern char *yp_server;
60 extern void yp_submit __P(( struct passwd * ));
61 extern int use_yp __P(( char * , uid_t , int ));
62 extern char *get_yp_master __P(( int ));
63 extern int yp_in_pw_file;
64
65 /*
66 * Yucky.
67 */
68 #define GETPWUID(X) \
69 _use_yp = use_yp(NULL, X, 1); \
70 \
71 if (_use_yp == USER_UNKNOWN) { \
72 errx(1, "unknown user: uid %u", X); \
73 } \
74 \
75 if (_use_yp == USER_YP_ONLY) { \
76 if (!force_local) { \
77 _use_yp = 1; \
78 pw = (struct passwd *)&yp_password; \
79 } else \
80 errx(1, "unknown local user: uid %u", X); \
81 } else if (_use_yp == USER_LOCAL_ONLY) { \
82 if (!force_yp) { \
83 _use_yp = 0; \
84 pw = (struct passwd *)&local_password; \
85 } else \
86 errx(1, "unknown NIS user: uid %u", X); \
87 } else if (_use_yp == USER_YP_AND_LOCAL) { \
88 if (!force_local && (force_yp || yp_in_pw_file)) { \
89 _use_yp = 1; \
90 pw = (struct passwd *)&yp_password; \
91 } else { \
92 _use_yp = 0; \
93 pw = (struct passwd *)&local_password; \
94 } \
95 }
96
97 #define GETPWNAM(X) \
98 _use_yp = use_yp(X, 0, 0); \
99 \
100 if (_use_yp == USER_UNKNOWN) { \
101 errx(1, "unknown user: %s", X); \
102 } \
103 \
104 if (_use_yp == USER_YP_ONLY) { \
105 if (!force_local) { \
106 _use_yp = 1; \
107 pw = (struct passwd *)&yp_password; \
108 } else \
109 errx(1, "unknown local user: %s.", X); \
110 } else if (_use_yp == USER_LOCAL_ONLY) { \
111 if (!force_yp) { \
112 _use_yp = 0; \
113 pw = (struct passwd *)&local_password; \
114 } else \
115 errx(1, "unknown NIS user: %s.", X); \
116 } else if (_use_yp == USER_YP_AND_LOCAL) { \
117 if (!force_local && (force_yp || yp_in_pw_file)) { \
118 _use_yp = 1; \
119 pw = (struct passwd *)&yp_password; \
120 } else { \
121 _use_yp = 0; \
122 pw = (struct passwd *)&local_password; \
123 } \
124 }
125
126 #endif /* YP */