How to capture password in c

This is a discussion on How to capture password in c within the C Programming forums, part of the General Programming Boards category; Hi I'm new to c. What I'm trying to do is much like httpd ssl. I'm trying to create a ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    How to capture password in c

    Hi

    I'm new to c. What I'm trying to do is much like httpd ssl. I'm trying to create a simple daemon where it will ask for a password/passphrase, and then check the password using pam. If the password/passphrase is wrong then the program should fail.

    My simple question is how do I do this?

    The full source code that I currently have is:

    Code:
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <unistd.h>
    #include <syslog.h>
    #include <string.h>
    
    int main(void) {
    
            /* Our process ID and Session ID */
            pid_t pid, sid;
    
            FILE *fin;
            int fwt;
            int c;
            #define BUFFER_LENGTH 50
            char line[BUFFER_LENGTH];
    
            /* Fork off the parent process */
            pid = fork();
            if (pid < 0) {
                    exit(EXIT_FAILURE);
            }
            /* If we got a good PID, then
            we can exit the parent process. */
            if (pid > 0) {
                    exit(EXIT_SUCCESS);
            }
    
            /* Change the file mode mask */
            umask(0);
    
            /* Open any logs here */
    
            /* Create a new SID for the child process */
            sid = setsid();
            if (sid < 0) {
                    /* Log the failure */
                    exit(EXIT_FAILURE);
            }
    
    
    
            /* Change the current working directory */
            if ((chdir("/")) < 0) {
                    /* Log the failure */
                    exit(EXIT_FAILURE);
            }
    
            /* Close out the standard file descriptors */
            close(STDIN_FILENO);
            close(STDOUT_FILENO);
            close(STDERR_FILENO);
    
            /* Daemon-specific initialization goes here */
    
            /* The Big Loop */
                    printf ("hello");
            while (1) {
                    printf ("hello");
                    /* Do some task here ... */
                    fin=fopen("/tmp/check","w");
                    fwt=fprintf(fin,"hello");
                    fclose(fin);
                    //while (getc(stdin) != NULL){
                    fgets(line,BUFSIZ,stdin);
    
                            printf("hello");
    
                    printf("error code is: %d\n",fwt);
    
    
                    sleep(30); /* wait 30 seconds */
            }
            exit(EXIT_SUCCESS);
    Thanks in advance for your help

    Dan
    Last edited by dan_track; 03-13-2006 at 02:52 AM.

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Please read this
    << !! Posting Code? Read this First !! >>

    and then edit your post

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    Ok

    Thanks for the tips. I've updated the post to include tags.

    Hope someone can help me.

    Thanks
    Dan

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    This makes no sense
    close(STDIN_FILENO);
    Followed by
    fgets(line,BUFSIZ,stdin);

    Writing daemons is not your normal newbie task.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A tenet connection from a C program..
    By ahmd2080 in forum Linux Programming
    Replies: 2
    Last Post: 07-04-2009, 03:42 AM
  2. Problem reading a password from a file.
    By medeshago in forum C Programming
    Replies: 15
    Last Post: 12-21-2008, 06:20 AM
  3. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 02:42 AM
  4. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21