I\'m trying to use setuid() and setgid() to set the respective id\'s of a program to drop privileges down from root, but to use them I need to know the uid and gid of the us
You want to use the getpw* family of system calls, generally in pwd.h. It's essentially a C-level interface to the information in /etc/passwd.