void rfbAuthInit(void)
{
  SecTypeData *s;
  int nSelected = 0;

  ReadConfigFile();

  for (s = secTypes; s->name != NULL; s++) {
    if (s->enabled) {
      nSelected++;
      if (!s->permitted) {
        rfbLog("WARNING: security type '%s' is not permitted\n", s->name);
        s->enabled = FALSE;
        continue;
      }
    }

    if (s->enabled) {
      nSecTypesEnabled++;
      rfbLog("Enabled security type '%s'\n", s->name);
      if (!s->rfbSecType->advertise) {
        s->rfbSecType->advertise = TRUE;
        rfbLog("Advertising security type '%s' to viewers\n",
               s->rfbSecType->name);
      }
    }
  }

  if (nSelected == 0) {
    /* No security type was selected.  See if we should enable the rfbAuthNone
       security type. */
    for (s = secTypes; s->name != NULL; s++) {
      if (!s->requiredData) {
        if (s->permitted) {
          nSecTypesEnabled++;
          s->enabled = TRUE;
          s->rfbSecType->advertise = TRUE;
          rfbLog("Enabled security type '%s'\n", s->name);
          rfbLog("Advertising security type '%s' to viewers\n",
                 s->rfbSecType->name);
        }
      } else {
        s->rfbSecType->advertise = FALSE;
      }
    }
  }

#ifndef XVNC_AuthPAM
  if (rfbOptPamAuth())
    rfbLog("WARNING: PAM support is not compiled in.\n");
#endif

  if (nSecTypesEnabled == 0) {
    for (s = secTypes; s->name != NULL; s++) {
      if (s->permitted)
        rfbLog("NOTICE: %s is a permitted security type\n", s->name);
    }

    FatalError("ERROR: no security types enabled!");
  } else {
    /* Do not advertise rfbAuthNone if any other security type is enabled */
    for (s = secTypes; s->name != NULL; s++) {
      if (s->enabled && strcmp(s->name, "none"))
        secTypeNone.advertise = FALSE;
    }
  }

#ifdef XVNC_AuthPAM
  if (rfbOptPamAuth() && rfbAuthUserACL) {
    struct passwd pbuf;
    struct passwd *pw;
    char buf[256];
    char *n;

    if (getpwuid_r(getuid(), &pbuf, buf, sizeof(buf), &pw) != 0)
      FatalError("AuthPAMUserPwdRspFunc: limit-user enabled and getpwuid_r failed: %s",
                 strerror(errno));

    n = (char *)rfbAlloc(strlen(pbuf.pw_name));
    strcpy(n, pbuf.pw_name);
    rfbAuthAddUser(n, FALSE);
  }
#endif
}
void rfbAuthInit(void)
{
  SecTypeData *s;
  int nSelected = 0;

  ReadConfigFile();

  for (s = secTypes; s->name != NULL; s++) {
    if (s->enabled) {
      nSelected++;
      if (!s->permitted) {
        rfbLog("WARNING: security type '%s' is not permitted\n", s->name);
        s->enabled = FALSE;
        continue;
      }
    }

    if (s->enabled) {
      nSecTypesEnabled++;
      rfbLog("Enabled security type '%s'\n", s->name);
      if (!s->rfbSecType->advertise) {
        s->rfbSecType->advertise = TRUE;
        rfbLog("Advertising security type '%s' to viewers\n",
               s->rfbSecType->name);
      }
    }
  }

  if (nSelected == 0) {
     
    for (s = secTypes; s->name != NULL; s++) {
      if (!s->requiredData) {
        if (s->permitted) {
          nSecTypesEnabled++;
          s->enabled = TRUE;
          s->rfbSecType->advertise = TRUE;
          rfbLog("Enabled security type '%s'\n", s->name);
          rfbLog("Advertising security type '%s' to viewers\n",
                 s->rfbSecType->name);
        }
      } else {
        s->rfbSecType->advertise = FALSE;
      }
    }
  }

#ifndef XVNC_AuthPAM
  if (rfbOptPamAuth())
    rfbLog("WARNING: PAM support is not compiled in.\n");
#endif

  if (nSecTypesEnabled == 0) {
    for (s = secTypes; s->name != NULL; s++) {
      if (s->permitted)
        rfbLog("NOTICE: %s is a permitted security type\n", s->name);
    }

    FatalError("ERROR: no security types enabled!");
  } else {
     
    for (s = secTypes; s->name != NULL; s++) {
      if (s->enabled && strcmp(s->name, "none"))
        secTypeNone.advertise = FALSE;
    }
  }

#ifdef XVNC_AuthPAM
  if (rfbOptPamAuth() && rfbAuthUserACL) {
    struct passwd pbuf;
    struct passwd *pw;
    char buf[256];
    char *n;

    if (getpwuid_r(getuid(), &pbuf, buf, sizeof(buf), &pw) != 0)
      FatalError("AuthPAMUserPwdRspFunc: limit-user enabled and getpwuid_r failed: %s",
                 strerror(errno));

    n = (char *)rfbAlloc(strlen(pbuf.pw_name));
    strcpy(n, pbuf.pw_name);
    rfbAuthAddUser(n, FALSE);
  }
#endif
}