2 Unix SMB/Netbios implementation.
4 Main SMB reply routines
5 Copyright (C) Andrew Tridgell 1992-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 /****************************************************************************
25 Read the a hosts.equiv or .rhosts file and check if it
26 allows this user from this machine.
27 ****************************************************************************/
29 static BOOL check_user_equiv(const char *user, const char *remote, const char *equiv_file)
34 char **lines = file_lines_load(equiv_file, NULL);
37 DEBUG(5, ("check_user_equiv %s %s %s\n", user, remote, equiv_file));
38 if (! lines) return False;
39 for (i=0; lines[i]; i++) {
41 trim_string(buf," "," ");
43 if (buf[0] != '#' && buf[0] != '\n')
45 BOOL is_group = False;
48 if (strcmp(buf, "NO_PLUS\n") == 0)
50 DEBUG(6, ("check_user_equiv NO_PLUS\n"));
57 if (*bp == '\n' && plus_allowed)
59 /* a bare plus means everbody allowed */
60 DEBUG(6, ("check_user_equiv everybody allowed\n"));
61 file_lines_free(lines);
65 else if (buf[0] == '-')
75 file_host = strtok(bp, " \t\n");
76 file_user = strtok(NULL, " \t\n");
77 DEBUG(7, ("check_user_equiv %s %s\n", file_host ? file_host : "(null)",
78 file_user ? file_user : "(null)" ));
79 if (file_host && *file_host)
83 #if defined(HAVE_NETGROUP) && defined(HAVE_YP_GET_DEFAULT_DOMAIN)
86 static char *mydomain = NULL;
88 yp_get_default_domain(&mydomain);
89 if (mydomain && innetgr(file_host,remote,user,mydomain))
95 DEBUG(1,("Netgroups not configured\n"));
100 /* is it this host */
101 /* the fact that remote has come from a call of gethostbyaddr
102 * means that it may have the fully qualified domain name
103 * so we could look up the file version to get it into
104 * a canonical form, but I would rather just type it
105 * in full in the equiv file
107 if (!host_ok && !is_group && strequal(remote, file_host))
113 /* is it this user */
114 if (file_user == 0 || strequal(user, file_user))
116 DEBUG(5, ("check_user_equiv matched %s%s %s\n",
117 (plus ? "+" : "-"), file_host,
118 (file_user ? file_user : "")));
119 file_lines_free(lines);
120 return (plus ? True : False);
126 file_lines_free(lines);
131 /****************************************************************************
132 check for a possible hosts equiv or rhosts entry for the user
133 ****************************************************************************/
135 static BOOL check_hosts_equiv(struct passwd *pass)
142 fname = lp_hosts_equiv();
144 /* note: don't allow hosts.equiv on root */
145 if (fname && *fname && (pass->pw_uid != 0)) {
146 if (check_user_equiv(pass->pw_name,client_name(),fname))
154 /****************************************************************************
155 Check for a valid .rhosts/hosts.equiv entry for this user
156 ****************************************************************************/
158 static NTSTATUS check_hostsequiv_security(const struct auth_context *auth_context,
159 void *my_private_data,
161 const auth_usersupplied_info *user_info,
162 auth_serversupplied_info **server_info)
164 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
165 struct passwd *pass = Get_Pwnam(user_info->internal_username.str);
168 if (check_hosts_equiv(pass)) {
169 nt_status = NT_STATUS_OK;
170 make_server_info_pw(server_info, pass);
173 nt_status = NT_STATUS_NO_SUCH_USER;
179 /* module initialisation */
180 BOOL auth_init_hostsequiv(struct auth_context *auth_context, auth_methods **auth_method)
182 if (!make_auth_methods(auth_context, auth_method)) {
186 (*auth_method)->auth = check_hostsequiv_security;
191 /****************************************************************************
192 Check for a valid .rhosts/hosts.equiv entry for this user
193 ****************************************************************************/
195 static NTSTATUS check_rhosts_security(const struct auth_context *auth_context,
196 void *my_private_data,
198 const auth_usersupplied_info *user_info,
199 auth_serversupplied_info **server_info)
201 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
202 struct passwd *pass = Get_Pwnam(user_info->internal_username.str);
206 char *home = pass->pw_dir;
208 slprintf(rhostsfile, sizeof(rhostsfile)-1, "%s/.rhosts", home);
210 if (check_user_equiv(pass->pw_name,client_name(),rhostsfile)) {
211 nt_status = NT_STATUS_OK;
212 make_server_info_pw(server_info, pass);
217 nt_status = NT_STATUS_NO_SUCH_USER;
223 /* module initialisation */
224 BOOL auth_init_rhosts(struct auth_context *auth_context, auth_methods **auth_method)
226 if (!make_auth_methods(auth_context, auth_method)) {
230 (*auth_method)->auth = check_rhosts_security;