/*
 * $Header: /home/gene/library/website/docsrc/show-uid/RCS/show-uid-c.c,v 395.1 2008/04/20 17:25:50 gene Exp $
 */

/* Standard C */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

/* Unix */
#include <pwd.h>
#include <sys/types.h>

static void S_Print (char str[])
{
  printf ("%s\r\n", str);
}

static void S_PrintA (char *a[], int length)
{
  int i;

  for (i = 0; i < length; ++i) {
    S_Print (a[i]);
  }
}

int
main ()
{
  int rc = 0;
  struct passwd *pw_real, *pw_eff;

  {
    static char *a[] = {
      "Content-type: text/html",
      "",
      "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"",
      "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",
      "<html xmlns=\"http://www.w3.org/1999.xhtml\">",
      "<h1>",
      "The Real &amp; Effective User in a",
      "<em>set-uid</em>",
      "Program Written in C",
      "</h1>",
      "<table border=\"1\">",
      "<tr> <th>real user</th> <th>effective user</th> </tr>"
    };
    static int alen = sizeof a / sizeof a[0];
    S_PrintA (a, alen);
  }

  pw_real = getpwuid (getuid ());
  pw_eff = getpwuid (geteuid ());
  printf ("<tr> <td>%s</td> <td>%s</td> </tr>\r\n",
          pw_real->pw_name, pw_eff->pw_name);

  {
    static char *b[] = {
      "</table>",
      "<p align=\"center\">End.</p>",
      "</body>",
      "</html>"
    };
    static int blen = sizeof b / sizeof b[0];
    S_PrintA (b, blen);
  }
  return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

/* --- end of file --- */
