document rlm_otp fd leak fix
[freeradius.git] / src / modules / rlm_smb / valid.c
1 /*
2  * valid.c
3  *
4  *   This program is free software; you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *   GNU General Public License for more details.
13  *
14  *   You should have received a copy of the GNU General Public License
15  *   along with this program; if not, write to the Free Software
16  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  *
18  * Copyright 2000  The FreeRADIUS server project
19  */
20
21 #include <sys/types.h>
22 #include <unistd.h>
23 #include <syslog.h>
24 #include "smblib-priv.h"
25 #include "valid.h"
26
27 SMB_Handle_Type SMB_Connect_Server(void *, char *, char *);
28
29 int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER,char *BACKUP, char *DOMAIN)
30 {
31   char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0",
32                             "MICROSOFT NETWORKS 1.03",
33                             "MICROSOFT NETWORKS 3.0",
34                             "LANMAN1.0",
35                             "LM1.2X002",
36                             "Samba",
37                             "NT LM 0.12",
38                             "NT LANMAN 1.0",
39                             NULL};
40   SMB_Handle_Type con;
41
42   SMB_Init();
43   con = SMB_Connect_Server(NULL, SERVER, DOMAIN);
44   if (con == NULL) { /* Error ... */
45    con = SMB_Connect_Server(NULL, BACKUP, DOMAIN);
46    if (con == NULL) {
47         return(NTV_SERVER_ERROR);
48    }
49   }
50   if (SMB_Negotiate(con, SMB_Prots) < 0) { /* An error */
51     SMB_Discon(con,0);
52     return(NTV_PROTOCOL_ERROR);
53   }
54   /* Test for a server in share level mode do not authenticate against it */
55   if (con -> Security == 0)
56     {
57       SMB_Discon(con,0);
58       return(NTV_PROTOCOL_ERROR);
59     }
60
61   if (SMB_Logon_Server(con, USERNAME, PASSWORD) < 0) {
62     SMB_Discon(con,0);
63     return(NTV_LOGON_ERROR);
64   }
65
66   SMB_Discon(con,0);
67   return(NTV_NO_ERROR);
68 }