00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <security/pam_appl.h>
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include <unistd.h>
00042
00043 const char pam_service[] = "irods";
00044 struct pam_response *reply;
00045
00046 int
00047 null_conv(int num_msg, const struct pam_message **msg,
00048 struct pam_response **resp, void *appdata_ptr) {
00049 *resp = reply;
00050 return PAM_SUCCESS;
00051 }
00052
00053 int main(int argc, char *argv[])
00054 {
00055 pam_handle_t *pamh=NULL;
00056 int retval;
00057 int nb;
00058 int debug=0;
00059
00060 static char password[500];
00061
00062 static char *username="nobody";
00063 static struct pam_conv conv = { null_conv, NULL };
00064
00065 if(argc == 2) {
00066 username = argv[1];
00067 }
00068 else {
00069 fprintf(stderr, "Usage: PamAuthCheck username\n");
00070 exit(2);
00071 }
00072
00073
00074 nb = read(0, (void*)&password, sizeof(password));
00075 if (debug>0) printf("nb=%d\n",nb);
00076 if (password[nb-1]=='\n') password[nb-1]='\0';
00077
00078 retval = pam_start(pam_service, username, &conv, &pamh);
00079 if (debug>0) printf("retval 1=%d\n",retval);
00080
00081 if (retval != PAM_SUCCESS) {
00082 fprintf(stderr, "PamAuthCheck: pam_start error\n");
00083 exit(3);
00084 }
00085
00086 reply = (struct pam_response*)malloc(sizeof(struct pam_response));
00087 if (reply == NULL) {
00088 fprintf(stderr, "PamAuthCheck: malloc error\n");
00089 exit(4);
00090 }
00091
00092 reply[0].resp = strdup(password);
00093 reply[0].resp_retcode = 0;
00094
00095 retval = pam_authenticate(pamh, 0);
00096 if (debug>0) printf("retval 2=%d\n",retval);
00097
00098 strcpy(password, " ");
00099
00100 if (retval == PAM_SUCCESS) {
00101 fprintf(stdout, "Authenticated\n");
00102 } else {
00103 fprintf(stdout, "Not Authenticated\n");
00104 }
00105
00106 if (pam_end(pamh,retval) != PAM_SUCCESS) {
00107 pamh = NULL;
00108 fprintf(stderr, "PamAuthCheck: failed to release authenticator\n");
00109 exit(5);
00110 }
00111
00112 return ( retval == PAM_SUCCESS ? 0:1 );
00113
00114
00115 }