import from branch_1_1:
[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,2006  The FreeRADIUS server project
19  */
20
21 #include <freeradius-devel/ident.h>
22 RCSID("$Id$")
23
24 #include <freeradius-devel/radiusd.h>
25
26 #include <syslog.h>
27 #include "smblib-priv.h"
28 #include "valid.h"
29
30 SMB_Handle_Type SMB_Connect_Server(void *, char *, char *);
31
32 int Valid_User(char *USERNAME,char *PASSWORD,char *SERVER,char *BACKUP, char *DOMAIN)
33 {
34   char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0",
35                             "MICROSOFT NETWORKS 1.03",
36                             "MICROSOFT NETWORKS 3.0",
37                             "LANMAN1.0",
38                             "LM1.2X002",
39                             "Samba",
40                             "NT LM 0.12",
41                             "NT LANMAN 1.0",
42                             NULL};
43   SMB_Handle_Type con;
44
45   SMB_Init();
46   con = SMB_Connect_Server(NULL, SERVER, DOMAIN);
47   if (con == NULL) { /* Error ... */
48    con = SMB_Connect_Server(NULL, BACKUP, DOMAIN);
49    if (con == NULL) {
50         return(NTV_SERVER_ERROR);
51    }
52   }
53   if (SMB_Negotiate(con, SMB_Prots) < 0) { /* An error */
54     SMB_Discon(con,0);
55     return(NTV_PROTOCOL_ERROR);
56   }
57   /* Test for a server in share level mode do not authenticate against it */
58   if (con -> Security == 0)
59     {
60       SMB_Discon(con,0);
61       return(NTV_PROTOCOL_ERROR);
62     }
63
64   if (SMB_Logon_Server(con, USERNAME, PASSWORD) < 0) {
65     SMB_Discon(con,0);
66     return(NTV_LOGON_ERROR);
67   }
68
69   SMB_Discon(con,0);
70   return(NTV_NO_ERROR);
71 }