Created
April 26, 2012 00:54
-
-
Save zenchild/2494905 to your computer and use it in GitHub Desktop.
A Linux preloader to preempt logins for apps with 8 char dependencies
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
gcc -fPIC -rdynamic -g -c -Wall getpwuid_preload64.c | |
gcc -fPIC -rdynamic -g -c -Wall getlogin_preload64.c | |
gcc -shared -WI,-soname,libcpreload64.so.1 -o libcpreload64.so.1.0.1 getpwuid_preload64.o getlogin_preload64.o -lc -ldl |
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
// Dan Wanek <[email protected]> | |
// This code was written to work around the 8 character login name issue | |
// with Natural and still allow users to have their Active Directory logins; | |
// which may in fact be longer than 8 characters. Users are assigned a group | |
// in AD that is actually their old RACF mainframe login. When logging in to | |
// Natural this library is called (vi LD_PRELOAD) and loads our own version of | |
// getpwuid which swaps out the real uid for the gid that has the same | |
// gidNumber as their uidNumber. This is the RACF id. Pretty sweet huh! :) | |
// | |
// Build: | |
// gcc -fPIC -rdynamic -g -c -Wall getpwuid_preload64.c | |
// gcc -shared -WI,-soname,libcpreload64.so.1 -o libcpreload64.so.1.0.1 getpwuid_preload64.o -lc -ldl | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <string.h> | |
#include <errno.h> | |
#include <unistd.h> | |
#include <pwd.h> | |
#include "include/getpwuid_preload64.h" | |
char *getlogin(void) { | |
char *login; | |
struct passwd *pwent; | |
uid_t uid; | |
// Get the uid of the current process | |
uid = getuid(); | |
pwent = sys_getpwuid(uid); | |
if(!pwent) { | |
if(errno == 0) { | |
fputs("User does not exist.\n",stderr); | |
exit(errno); | |
} else { | |
fputs("Error getting group: => ",stderr); | |
char* err = strerror(errno); | |
fputs(err,stderr); | |
fputs("\n",stderr); | |
} | |
exit(errno); | |
} | |
login = pwent->pw_name; | |
return(login); | |
} |
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
// Dan Wanek <[email protected]> | |
// This code was written to work around the 8 character login name issue | |
// with Natural and still allow users to have their Active Directory logins; | |
// which may in fact be longer than 8 characters. Users are assigned a group | |
// in AD that is actually their old RACF mainframe login. When logging in to | |
// Natural this library is called (vi LD_PRELOAD) and loads our own version of | |
// getpwuid which swaps out the real uid for the gid that has the same | |
// gidNumber as their uidNumber. This is the RACF id. Pretty sweet huh! :) | |
// | |
// Build: | |
// gcc -fPIC -rdynamic -g -c -Wall getpwuid_preload64.c | |
// gcc -fPIC -rdynamic -g -c -Wall getlogin_preload64.c | |
// gcc -shared -WI,-soname,libcpreload64.so.1 -o libcpreload64.so.1.0.1 getpwuid_preload64.o getlogin_preload64.o -lc -ldl | |
// | |
#include "include/getpwuid_preload64.h" | |
struct passwd *sys_getpwuid(uid_t uid) { | |
void *clib; | |
struct passwd *(*sys_getpwuid)(uid_t); | |
struct passwd *pass; | |
clib = dlopen("/lib64/libnss_ldap.so.2",RTLD_LAZY); | |
if(!clib) { | |
fputs(dlerror(), stderr); | |
exit(EXIT_FAILURE); | |
} | |
sys_getpwuid = dlsym(clib,"getpwuid"); | |
pass = sys_getpwuid(uid); | |
return(pass); | |
} | |
struct passwd *getpwuid(uid_t uid) { | |
struct passwd *pass; | |
struct group *grp; | |
pass = sys_getpwuid(uid); | |
if(!pass) { | |
fputs("Error: => ",stderr); | |
char* err = strerror(errno); | |
fputs(err,stderr); | |
fputs("\n",stderr); | |
exit(errno); | |
} | |
// Get the group struct where gidNumber == uidNumber (i.e. RACF login) | |
grp = getgrgid(uid); | |
if(!grp) { | |
if(errno == 0) { | |
fputs("RACF User does not exist.\n",stderr); | |
exit(errno); | |
} else { | |
fputs("Error getting group: => ",stderr); | |
char* err = strerror(errno); | |
fputs(err,stderr); | |
fputs("\n",stderr); | |
} | |
exit(errno); | |
} | |
// Parse RACF- from the gid name | |
char *newpw_name; | |
newpw_name = strdup(grp->gr_name); | |
strsep(&newpw_name,"-"); | |
// Now do the swap. Set the pw_name to the RACF id. | |
pass->pw_name = newpw_name; | |
return(pass); | |
} |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <dlfcn.h> | |
#include <sys/types.h> | |
#include <pwd.h> | |
#include <grp.h> | |
#include <string.h> | |
#include <errno.h> | |
#include <unistd.h> | |
struct passwd *sys_getpwuid(uid_t uid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment