]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - chpass/pw_yp.h
Switch to user UID/GID before checking/reading its ~/.login_conf
[pw-darwin.git] / chpass / pw_yp.h
index 94c7a74090d2b9c86f7233bd9824c905e469f6bd..0a1e1c0573d9cbe4763f2725e4a0321ef12ceee5 100644 (file)
  */
 
 #ifdef YP
+#include <sys/types.h>
+#include <rpc/rpc.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+/* Four possible return codes from use_yp() */
+#define USER_UNKNOWN 0
+#define USER_YP_ONLY 1
+#define USER_LOCAL_ONLY 2
+#define USER_YP_AND_LOCAL 3
+
+extern int             force_old;
 extern int             _use_yp;
-void   yp_submit       __P(( struct passwd * ));
-int    use_yp          __P(( char * ));
+extern int             suser_override;
+extern struct passwd   local_password;
+extern struct passwd   yp_password;
+extern void            copy_yp_pass __P(( char *, int, int ));
+extern char            *yp_domain;
+extern char            *yp_server;
+extern void            yp_submit       __P(( struct passwd * ));
+extern int             use_yp          __P(( char * , uid_t , int ));
+extern char            *get_yp_master  __P(( int ));
+extern int             yp_in_pw_file;
+
+/*
+ * Yucky.
+ */
+#define GETPWUID(X) \
+       _use_yp = use_yp(NULL, X, 1);                                   \
+                                                                       \
+       if (_use_yp == USER_UNKNOWN) {                                  \
+               errx(1, "unknown user: uid %u", X);                     \
+       }                                                               \
+                                                                       \
+       if (_use_yp == USER_YP_ONLY) {                                  \
+               if (!force_local) {                                     \
+                       _use_yp = 1;                                    \
+                       pw = (struct passwd *)&yp_password;             \
+               } else                                                  \
+                       errx(1, "unknown local user: uid %u", X);       \
+       } else if (_use_yp == USER_LOCAL_ONLY) {                        \
+               if (!force_yp) {                                        \
+                       _use_yp = 0;                                    \
+                       pw = (struct passwd *)&local_password;          \
+               } else                                                  \
+                       errx(1, "unknown NIS user: uid %u", X);         \
+       } else if (_use_yp == USER_YP_AND_LOCAL) {                      \
+               if (!force_local && (force_yp || yp_in_pw_file)) {      \
+                       _use_yp = 1;                                    \
+                       pw = (struct passwd *)&yp_password;             \
+               } else {                                                \
+                       _use_yp = 0;                                    \
+                       pw = (struct passwd *)&local_password;          \
+               }                                                       \
+       }
+
+#define GETPWNAM(X) \
+       _use_yp = use_yp(X, 0, 0);                                      \
+                                                                       \
+       if (_use_yp == USER_UNKNOWN) {                                  \
+               errx(1, "unknown user: %s", X);                         \
+       }                                                               \
+                                                                       \
+       if (_use_yp == USER_YP_ONLY) {                                  \
+               if (!force_local) {                                     \
+                       _use_yp = 1;                                    \
+                       pw = (struct passwd *)&yp_password;             \
+               } else                                                  \
+                       errx(1, "unknown local user: %s.", X);          \
+       } else if (_use_yp == USER_LOCAL_ONLY) {                        \
+               if (!force_yp) {                                        \
+                       _use_yp = 0;                                    \
+                       pw = (struct passwd *)&local_password;          \
+               } else                                                  \
+                       errx(1, "unknown NIS user: %s.", X);            \
+       } else if (_use_yp == USER_YP_AND_LOCAL) {                      \
+               if (!force_local && (force_yp || yp_in_pw_file)) {      \
+                       _use_yp = 1;                                    \
+                       pw = (struct passwd *)&yp_password;             \
+               } else {                                                \
+                       _use_yp = 0;                                    \
+                       pw = (struct passwd *)&local_password;          \
+               }                                                       \
+       }
+
 #endif /* YP */