• How to Read file descriptor 3 in C

    Amit Member

    File descriptors are usually assigned in order. 0, 1, and 2 are reserved. 3 would be the first file descriptor opened by the program. The descriptor is just a number is simply an index into a table (owned by the process) that then indexes into the system table.

    The descriptor can refer to any file or file type in the system. What I would expect in this case is that the first program opens a pipe that is to be read by your password program. It’s the first thing that the program opens so its descriptor is 3.

    You can’t redirect things to a file descriptor called 3 because it is not a standard file descriptor. It doesn’t exist, except within the scope of your process if you open it or any other process that inherits it from your process.

    his impiles to me that it possibly opens the fd 3, then runs the checkpassword program from within qmail-popup … as a child.

  • Adan Member

    I think I’ve got it! I created the program ckpw.c as shown below. I used pipe() which creates an fd array with fd[0] for input and fd[1] for output (apparently). The output of my ckpw program shows fd[0] =3, and fd[1] = 4. I used execve() to launch the checkpassword program.

    I don’t really know how my real invoker (Dovecot) launches checkpassword, but this should give me a start.

    Test Results:

    $ ckpw
    fd[0] (read): 3, fd[1] (write) 4
    entered checkpassword
    finished reading
    15: Hello, world!
    
  • Amit Member

    My test program that calls execve is simulating the real one in the mail facility. I’ve bolted my finished checkpassword program into the mail stream and it is getting the right info.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish