-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RANGER-842: modified to create a separate module for PAM credential v…
…alidation Signed-off-by: rmani <[email protected]>
- Loading branch information
1 parent
42d8db5
commit 5ba4831
Showing
9 changed files
with
219 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target/ | ||
/bin/ | ||
.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.ranger</groupId> | ||
<artifactId>ranger</artifactId> | ||
<version>0.6.0-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
<artifactId>pamCredValidator</artifactId> | ||
<packaging>uexe</packaging> | ||
<name>PAM Authenticator</name> | ||
<description>PAM authentication service</description> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>native-maven-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<compilerStartOptions> | ||
<compilerStartOption>${commonCompilerOptions}</compilerStartOption> | ||
</compilerStartOptions> | ||
<sources> | ||
<source> | ||
<directory>src/main/c</directory> | ||
<includes> | ||
<include>**/*.c</include> | ||
</includes> | ||
</source> | ||
</sources> | ||
<linkerEndOptions> | ||
<linkerEndOption>-lpam</linkerEndOption> | ||
</linkerEndOptions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
You need to add the following (or equivalent) to the | ||
/etc/pam.d/ranger-remote file: | ||
# check authorization | ||
auth required pam_unix.so | ||
account required pam_unix.so | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdarg.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <pwd.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <security/pam_appl.h> | ||
|
||
int pamconv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) { | ||
if (num_msg != 1 || msg[0]->msg_style != PAM_PROMPT_ECHO_OFF) { | ||
fprintf(stderr, "ERROR: Unexpected PAM conversation '%d/%s'\n", msg[0]->msg_style, msg[0]->msg); | ||
return PAM_CONV_ERR; | ||
} | ||
if (!appdata_ptr) { | ||
fprintf(stderr, "ERROR: No password available to conversation!\n"); | ||
return PAM_CONV_ERR; | ||
} | ||
*resp = calloc(num_msg, sizeof(struct pam_response)); | ||
if (!*resp) { | ||
fprintf(stderr, "ERROR: Out of memory!\n"); | ||
return PAM_CONV_ERR; | ||
} | ||
(*resp)[0].resp = strdup((char *) appdata_ptr); | ||
(*resp)[0].resp_retcode = 0; | ||
|
||
return ((*resp)[0].resp ? PAM_SUCCESS : PAM_CONV_ERR); | ||
} | ||
|
||
struct pam_conv conv = { pamconv, NULL }; | ||
|
||
int main(int ac, char **av, char **ev) | ||
{ | ||
char username[64] ; | ||
char password[64] ; | ||
char line[512] ; | ||
|
||
int retval; | ||
pam_handle_t *pamh = NULL; | ||
|
||
fgets(line,512,stdin) ; | ||
sscanf(line, "LOGIN:%s %s",username,password) ; | ||
conv.appdata_ptr = (char *) password; | ||
|
||
retval = pam_start("ranger-remote", username, &conv, &pamh); | ||
if (retval != PAM_SUCCESS) { | ||
/* why expose this? */ | ||
fprintf(stdout, "FAILED: [%s] does not exists.\n", username) ; | ||
exit(1); | ||
} | ||
|
||
retval = pam_authenticate(pamh, 0); | ||
if (retval != PAM_SUCCESS) { | ||
fprintf(stdout, "FAILED: Password did not match.\n") ; | ||
exit(1); | ||
} | ||
|
||
/* authorize */ | ||
retval = pam_acct_mgmt(pamh, 0); | ||
if (retval != PAM_SUCCESS) { | ||
fprintf(stdout, "FAILED: [%s] is not authorized.\n", username) ; | ||
exit(1); | ||
} | ||
|
||
/* establish the requested credentials */ | ||
if ((retval = pam_setcred(pamh, PAM_ESTABLISH_CRED)) != PAM_SUCCESS) { | ||
fprintf(stdout, "FAILED: Error setting credentials for [%s].\n", username) ; | ||
exit(1); | ||
} | ||
|
||
/* not opening a session, as logout has not been implemented as a remote service */ | ||
fprintf(stdout, "OK:\n") ; | ||
|
||
if (pamh) { | ||
pam_end(pamh, retval); | ||
} | ||
|
||
exit(0) ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters