Permalink
Browse files

Fixed double free errors, added more comments ftw

  • Loading branch information...
1 parent 4d5dfc5 commit 4fe9f2cb7eea6af70ad7b695a6009d6cd1400b36 @ditesh committed Jun 13, 2011
Showing with 31 additions and 18 deletions.
  1. +5 −1 README
  2. +10 −2 demo/demo.js
  3. +16 −15 pam.cc
View
6 README
@@ -1 +1,5 @@
-PAM authentication module for NodeJS.
+PAM authentication module for NodeJS. Not libeio based, yet.
+
+Tested on NodeJS 0.4.8, with PAM on Fedora 15.
+
+A note that I've used service name "system-auth" on Fedora 15 without a problem.
View
@@ -1,5 +1,13 @@
var pamlib = require('../build/default/pam.node');
var pam = new pamlib.PAM();
-console.log("Username: ditesh, password: mypass, output: " + pam.authenticate("system-auth", "ditesh", 'mypass')); // should output false
-console.log("Username: ditesh, password: mypass, output: " + pam.authenticate("system-auth", "ditesh", 'efg')); // should output true
+
+// This should output false because (clearly) your username is not myusername
+// and your password is mypassword. Change it and it should work!
+
+// PAM service name. On Fedora 15, standard system auth service name is system-auth.
+// Change accordingly or write your own.
+var service = "system-auth";
+var username = "myusername";
+var password = "mypassword";
+console.log("Username: " + username + ", password: " + password + ", output: " + pam.authenticate(service, username, password));
View
31 pam.cc
@@ -1,5 +1,6 @@
#include <v8.h>
#include <node.h>
+#include <string.h>
#include <stdlib.h>
#include <typeinfo>
#include <iostream>
@@ -9,7 +10,6 @@ struct pam_response *reply;
int null_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) {
- printf("in nullconv");
*resp = reply;
return PAM_SUCCESS;
@@ -21,24 +21,26 @@ const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
}
-int _pam_authenticate(char *service, char *username, char *password) {
+extern "C" {
+ int _pam_authenticate(char *service, char *username, char *password) {
- pam_handle_t *pamh = NULL;
- int retval = pam_start(service, username, &conv, &pamh);
+ pam_handle_t *pamh = NULL;
+ int retval = pam_start(service, username, &conv, &pamh);
- if (retval == PAM_SUCCESS) {
+ if (retval == PAM_SUCCESS) {
- reply = (struct pam_response *) malloc(sizeof(struct pam_response));
- reply[0].resp = password;
- reply[0].resp_retcode = 0;
+ reply = (struct pam_response *) malloc(sizeof(struct pam_response));
+ reply[0].resp = password;
+ reply[0].resp_retcode = 0;
- retval = pam_authenticate(pamh, 0);
- pam_end(pamh, PAM_SUCCESS);
+ retval = pam_authenticate(pamh, 0);
+ pam_end(pamh, PAM_SUCCESS);
- }
+ }
- return retval;
+ return retval;
+ }
}
using namespace node;
@@ -84,13 +86,12 @@ private: int m_count;
v8::String::Utf8Value password(args[2]);
bool result = false;
- int retval = _pam_authenticate((char *) ToCString(service), (char *) ToCString(username), (char *) ToCString(password));
+ int retval = _pam_authenticate(strdup((char *) ToCString(service)), strdup((char *) ToCString(username)), strdup((char *) ToCString(password)));
if (retval == PAM_SUCCESS)
result = true;
- Local<String> ret = String::New("abc");
- return ret;//scope.Close(ret);
+ return Boolean::New(result);
}
};

0 comments on commit 4fe9f2c

Please sign in to comment.