Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 911970 Details for
Bug 1110209
getlogin failed (ENOENT) after forkpty in child process
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
test code for su failed after configuring su in pam
sutest.cpp (text/plain), 4.19 KB, created by
daisy.shang
on 2014-06-25 08:02:24 UTC
(
hide
)
Description:
test code for su failed after configuring su in pam
Filename:
MIME Type:
Creator:
daisy.shang
Created:
2014-06-25 08:02:24 UTC
Size:
4.19 KB
patch
obsolete
>#include <stdlib.h> >#include <stdio.h> >#include <pty.h> >#include <utmp.h> >#include <errno.h> >#include <string.h> >#include <unistd.h> >#include <sys/types.h> >#include <sys/wait.h> > >#define BUF_SIZE 256 >#define TIME_OUT_VALUE 60 >#define COMMON_LEN 128 >#define PATH_MAX 1024 > > >int SuperExecuteCmdEx(const char *user, const char *pwd, const char *cmd=NULL, int block=1, int mytimeout=-1/*<=0 means wait infinate*/, char *output=NULL, int outputSize=0); >int SuperExecuteCmdEx(const char *user, const char *pwd, const char *cmd, int block, int mytimeout/*<=0 means wait infinate*/, char *output, int outputSize) { > int masterFd = 0; > fd_set inFds; > struct timeval tv = {0l,0l}; > char buf[BUF_SIZE] = {0}; > ssize_t numRead = 0; > char password[COMMON_LEN] = {0}; > char *argv[5] = {NULL}; > char command[PATH_MAX] = {0}; > > if ( user == NULL || pwd == NULL ) return -1; > > //time out is 30s > tv.tv_sec = TIME_OUT_VALUE; > > if ( cmd == NULL ) { > strncat(command, "id", sizeof(command)-1-strlen(command)); > } else { > strncat(command, cmd, sizeof(command)-1-strlen(command)); > } > > snprintf(password, sizeof(password)-1, "%s\n", pwd); //\n is important > > argv[0] = "su"; > argv[1] = (char*)(user==NULL ? "root" : user); > argv[2] = "-mc"; //need preserve env > argv[3] = &command[0]; > > > pid_t pid=forkpty(&masterFd, NULL, NULL, NULL); > switch (pid) { > case -1: > return -1; > case 0: //Child > { > char *ln = getlogin(); > } > if ( execvp(argv[0], argv) == -1 ) { //need preserve env here > return errno; > } > default: //Parent > > FD_ZERO(&inFds); > FD_SET(masterFd, &inFds); >AGAIN: > if (select(masterFd + 1, &inFds, NULL, NULL, &tv) == -1) { > if ( errno == EINTR ) { > goto AGAIN; > } > close(masterFd); > return -2; > } > > if (FD_ISSET(masterFd, &inFds)) { > numRead = read(masterFd, buf, sizeof(buf)-1); > if (numRead <= 0) { > close(masterFd); > return -3; > } > > buf[numRead]=0; > > if (write(masterFd, password, strlen(password)) != (int)strlen(password)) //feed password > { > close(masterFd); > return -4; > } > > memset(buf, 0, sizeof(buf)); > read(masterFd, buf, sizeof(buf));//this for reading the written passwd above or the line terminitor \r\n > > if ( block == 1 ) { > int status = 0; > int ret = -1; > if ( mytimeout > 0 ) { > int timeElapse=0; > while ( timeElapse++ < mytimeout ) { > ret = waitpid(pid, &status,WNOHANG); > if ( ret == -1 ) { > close(masterFd); > return -6; > } else if ( ret == pid ) { > break; > } else { > sleep(1); > } > } > > if ( timeElapse >= mytimeout ) { > if (write(masterFd, "\n", strlen("\n")) != (int)strlen("\n")) //write \n to read the output > { > > } else { > memset(buf, 0, sizeof(buf)); > numRead = read(masterFd, buf, sizeof(buf)-1);//this for reading the output of su or command > if ( numRead > 0 ) { > if ( strstr(buf, "Changing password for") != NULL ) { > if ( output != NULL && outputSize > 0 ) { > strncpy(output,"1",outputSize); > } > return 1;//1 means invalid password > } > } > } > > return -9; > } > } else { > if ( waitpid(pid, &status,0) == -1 ) { > close(masterFd); > return -6; > } > } > > if ( WIFEXITED(status) ) { > //read the output of cmd > if ( output != NULL && outputSize > 0 ) { > numRead = read(masterFd, output, outputSize-1); > if (numRead < 0) { > strncpy(output, buf, outputSize); > } else { > output[numRead]=0; > } > > //ProcessSudoOutput(output, outputSize); > } > ret = WEXITSTATUS(status); > return ret; > } else { > close(masterFd); > return -7; > } > } else { > return 0; > } > } else { > close(masterFd); > return -5; > } > } > > close(masterFd); > return 0; >} > >int main(int argc, char **argv) >{ > if ( argc < 3 ) { > printf("usage: test root password\n"); > return -1; > } > uid_t uid = getuid(); > if ( uid == 0 ) { > printf("please login with non-root user\n"); > return -2; > } > char buf[256] = {0}; > int ret = SuperExecuteCmdEx(argv[1], argv[2], "id", 1, -1, buf, sizeof(buf)-1); > printf("output is: %s\n", buf); > return ret; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1110209
: 911970