/*
 * smb.c - pppd plugin to use NT domain authentication
 *
 * John Newbigin
 *
 */
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include <syslog.h>
#include <stdlib.h>
#include "pppd.h"

int check_user(char *user, char *passwd);

int smb_pap_check_hook(void)
{
	// we always want an authentication attempt
	return 1;
}

/*
// This is used when we are supplying a password
// Not needed as we are checking the password
int smb_pap_passwd_hook(char *user, char *passwd)
{
}
*/

char *successMessage = "Success";
char *failMessage = "Authentication Failed";

int smb_pap_auth_hook(char *user,
                     char *passwd,
                     char **msgp,
                     struct wordlist **paddrs,
                     struct wordlist **popts)
{
    struct wordlist *wp;
    char *addr = "*";
    int l = strlen(addr);

	if(check_user(user, passwd) == 0)	
	{
		*msgp = successMessage;

		// add a wildcard address....?

    wp = (struct wordlist *) malloc(sizeof(struct wordlist) + l + 1);
    /*if (wp == NULL)
        novm("allow-ip argument");*/
    wp->word = (char *) (wp + 1);
    wp->next = *paddrs;
    BCOPY(addr, wp->word, l);

	*paddrs = wp;
 

		return 1;
	}
	else
	{
		*msgp = failMessage;
		return 0;
	}
}


void plugin_init(void)
{
//    add_options(options);
	pap_check_hook = smb_pap_check_hook;
    //pap_passwd_hook = smb_pap_passwd_hook;
	pap_auth_hook = smb_pap_auth_hook;
}

