Removed file handling, working ove buffer now. Almost beta state now!!!
This commit is contained in:
parent
8300c3ed9e
commit
b1c345d16d
3 changed files with 34 additions and 38 deletions
|
@ -1,7 +1,7 @@
|
|||
CFLAGS += -fPIC -Wall
|
||||
|
||||
ifdef DEBUG
|
||||
CFLAGS += -O0 -ggdb
|
||||
CFLAGS += -O0 -ggdb -DDEBUG=1
|
||||
else
|
||||
CFLAGS += -O2
|
||||
endif
|
||||
|
|
|
@ -16,19 +16,19 @@ if( isset($_POST["user"]) && isset($_POST["pass"]) && isset($_POST["mode"]) )
|
|||
|
||||
switch($_POST["mode"])
|
||||
{
|
||||
case "PAM_AUTH";
|
||||
case "PAM_SM_AUTH";
|
||||
// Perform authing here
|
||||
break;
|
||||
|
||||
case "PAM_ACCT";
|
||||
case "PAM_SM_ACCOUNT";
|
||||
// Perform account aging here
|
||||
break;
|
||||
|
||||
case "PAM_SESS";
|
||||
case "PAM_SM_SESSION";
|
||||
// Perform session management here
|
||||
break;
|
||||
|
||||
case "PAM_PASS";
|
||||
case "PAM_SM_PASSWORD";
|
||||
// Perform password changes here
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -91,11 +91,10 @@ typedef struct pam_url_opts_ {
|
|||
|
||||
const void* user;
|
||||
const void* passwd;
|
||||
|
||||
FILE* answer;
|
||||
char* fanswer;
|
||||
} pam_url_opts;
|
||||
|
||||
char* recvbuff = NULL;
|
||||
|
||||
void notice(pam_handle_t* pamh, const char *msg)
|
||||
{
|
||||
pam_syslog(pamh, LOG_NOTICE, "%s", msg);
|
||||
|
@ -103,7 +102,9 @@ void notice(pam_handle_t* pamh, const char *msg)
|
|||
|
||||
void debug(pam_handle_t* pamh, const char *msg)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
pam_syslog(pamh, LOG_ERR, "%s", msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
int get_password(pam_handle_t* pamh, pam_url_opts* opts)
|
||||
|
@ -174,9 +175,6 @@ int parse_opts(pam_url_opts* opts, int argc, const char** argv, int mode)
|
|||
strcpy(opts->extrafield, argv[4]);
|
||||
}
|
||||
|
||||
opts->fanswer = calloc(1, strlen(tmpnam(NULL)) + 1 );
|
||||
strcpy(opts->fanswer, tmpnam(NULL));
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case PAM_SM_ACCOUNT:
|
||||
|
@ -199,15 +197,21 @@ int parse_opts(pam_url_opts* opts, int argc, const char** argv, int mode)
|
|||
strcpy(opts->mode,"PAM_SM_AUTH");
|
||||
}
|
||||
|
||||
|
||||
if( NULL == (opts->answer = fopen(opts->fanswer, "w+")) )
|
||||
{
|
||||
return PAM_AUTH_ERR;
|
||||
}
|
||||
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
size_t curl_wf(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
if( NULL == recvbuff )
|
||||
recvbuff = calloc(1, strlen(ptr) + 1);
|
||||
|
||||
recvbuff = realloc(recvbuff, strlen(recvbuff) + strlen(ptr) + 1);
|
||||
|
||||
strncat(recvbuff, ptr, sizeof(recvbuff));
|
||||
|
||||
return size*nmemb;
|
||||
}
|
||||
|
||||
int fetch_url(pam_url_opts opts)
|
||||
{
|
||||
CURL* eh = NULL;
|
||||
|
@ -238,6 +242,14 @@ int fetch_url(pam_url_opts opts)
|
|||
if( NULL == (eh = curl_easy_init() ) )
|
||||
return PAM_AUTH_ERR;
|
||||
|
||||
#ifdef DEBUG
|
||||
if( CURLE_OK != curl_easy_setopt(eh, CURLOPT_VERBOSE, 1) )
|
||||
{
|
||||
curl_easy_cleanup(eh);
|
||||
return PAM_AUTH_ERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( CURLE_OK != curl_easy_setopt(eh, CURLOPT_POSTFIELDS, post) )
|
||||
{
|
||||
curl_easy_cleanup(eh);
|
||||
|
@ -250,7 +262,7 @@ int fetch_url(pam_url_opts opts)
|
|||
return PAM_AUTH_ERR;
|
||||
}
|
||||
|
||||
if( CURLE_OK != curl_easy_setopt(eh, CURLOPT_WRITEDATA, opts.answer) )
|
||||
if( CURLE_OK != curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, curl_wf) )
|
||||
{
|
||||
curl_easy_cleanup(eh);
|
||||
return PAM_AUTH_ERR;
|
||||
|
@ -295,31 +307,15 @@ int fetch_url(pam_url_opts opts)
|
|||
int check_psk(pam_url_opts opts)
|
||||
{
|
||||
int ret=0;
|
||||
char* buf;
|
||||
|
||||
if( 0 != access( opts.fanswer, R_OK|W_OK ) || NULL == opts.answer )
|
||||
if( NULL == recvbuff )
|
||||
{
|
||||
ret++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
rewind(opts.answer);
|
||||
|
||||
// buf = calloc(1, 2000);
|
||||
|
||||
if( NULL == fgets(buf, sizeof(buf),opts.answer) )
|
||||
{
|
||||
ret++;
|
||||
rewind(opts.answer);
|
||||
return PAM_AUTH_ERR;
|
||||
}
|
||||
|
||||
if( 0 != strncmp(buf, opts.PSK, strlen(opts.PSK)) )
|
||||
{
|
||||
if( 0 != strncmp(opts.PSK, recvbuff, strlen(opts.PSK)) )
|
||||
ret++;
|
||||
}
|
||||
|
||||
rewind(opts.answer);
|
||||
|
||||
if( 0 != ret )
|
||||
{
|
||||
|
@ -333,8 +329,8 @@ int check_psk(pam_url_opts opts)
|
|||
|
||||
void cleanup(pam_url_opts opts)
|
||||
{
|
||||
fclose(opts.answer);
|
||||
remove(opts.fanswer);
|
||||
if( NULL != recvbuff )
|
||||
free(recvbuff);
|
||||
}
|
||||
|
||||
PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue