"Fossies" - the Fresh Open Source Software Archive

Member "mod_ntlm2-0.1/smbval/valid.inc.c" (21 Feb 2003, 2641 Bytes) of package /linux/www/apache_httpd_modules/old/mod_ntlm2-0.1.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* mod_ntlm file: $Id: valid.inc.c,v 1.2 2003/02/21 01:55:14 casz Exp $ */
    2 
    3 #include <sys/types.h>
    4 #include <unistd.h>
    5 #include <syslog.h>
    6 #include "smblib-priv.h"
    7 #include "valid.h"
    8 
    9 static SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type, char *, char *);
   10 
   11 static int 
   12 Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP, char *DOMAIN)
   13 {
   14     char *SMB_Prots[] =
   15     {"PC NETWORK PROGRAM 1.0",
   16      "MICROSOFT NETWORKS 1.03",
   17      "MICROSOFT NETWORKS 3.0",
   18      "LANMAN1.0",
   19      "LM1.2X002",
   20      "Samba",
   21      "NT LM 0.12",
   22      "NT LANMAN 1.0",
   23      NULL};
   24     SMB_Handle_Type con;
   25 
   26     SMB_Init();
   27     con = SMB_Connect_Server(NULL, SERVER, DOMAIN);
   28     if (con == NULL) {          /* Error ... */
   29         con = SMB_Connect_Server(NULL, BACKUP, DOMAIN);
   30         if (con == NULL) {
   31             return (NTV_SERVER_ERROR);
   32         }
   33     }
   34     if (SMB_Negotiate(con, SMB_Prots) < 0) {    /* An error */
   35         SMB_Discon(con, 0);
   36         return (NTV_PROTOCOL_ERROR);
   37     }
   38     /* Test for a server in share level mode do not authenticate against
   39      * it */
   40     if (con->Security == 0) {
   41         SMB_Discon(con, 0);
   42         return (NTV_PROTOCOL_ERROR);
   43     }
   44     if (SMB_Logon_Server(con, USERNAME, PASSWORD, 0) < 0) {
   45         SMB_Discon(con, 0);
   46         return (NTV_LOGON_ERROR);
   47     }
   48     SMB_Discon(con, 0);
   49     return (NTV_NO_ERROR);
   50 }
   51 
   52 static void *
   53 NTLM_Connect(char *SERVER, char *BACKUP, char *DOMAIN, char *nonce)
   54 {
   55     char *SMB_Prots[] =
   56     {"PC NETWORK PROGRAM 1.0",
   57      "MICROSOFT NETWORKS 1.03",
   58      "MICROSOFT NETWORKS 3.0",
   59      "LANMAN1.0",
   60      "LM1.2X002",
   61      "Samba",
   62      "NT LM 0.12",
   63      "NT LANMAN 1.0",
   64      NULL};
   65     SMB_Handle_Type con;
   66 
   67     SMB_Init();
   68     con = SMB_Connect_Server(NULL, SERVER, DOMAIN);
   69     if (con == NULL) {          /* Error ... */
   70         con = SMB_Connect_Server(NULL, BACKUP, DOMAIN);
   71         if (con == NULL) {
   72             return (NULL);
   73         }
   74     }
   75     if (SMB_Negotiate(con, SMB_Prots) < 0) {    /* An error */
   76         SMB_Discon(con, 0);
   77         return (NULL);
   78     }
   79     /* Test for a server in share level mode do not authenticate
   80      * against it */
   81     if (con->Security == 0) {
   82         SMB_Discon(con, 0);
   83         return (NULL);
   84     }
   85     memcpy(nonce, con->Encrypt_Key, 8);
   86 
   87     return con;
   88 }
   89 
   90 static int 
   91 NTLM_Auth(void *handle, char *USERNAME, char *PASSWORD, int flag)
   92 {
   93     SMB_Handle_Type con = handle;
   94 
   95     if (SMB_Logon_Server(con, USERNAME, PASSWORD, flag) < 0) {
   96         return (NTV_LOGON_ERROR);
   97     }
   98     return NTV_NO_ERROR;
   99 }
  100 
  101 static void 
  102 NTLM_Disconnect(void *handle)
  103 {
  104     SMB_Handle_Type con = handle;
  105     SMB_Discon(con, 0);
  106 }