怎么开启从文件中读取密码!!代码如下..这个是openvpn的开源代码。想编译下WINDOWS下的 客户端让他能从文件中读取密码!!
* Get and store a username/password
 */bool
get_user_pass (struct user_pass *up,
       const char *auth_file,
       const char *prefix,
       const unsigned int flags)
{
  struct gc_arena gc = gc_new ();  if (!up->defined)
    {
      const bool from_stdin = (!auth_file || !strcmp (auth_file, "stdin"));#ifdef ENABLE_MANAGEMENT
      /*
       * Get username/password from standard input?
       */
      if (management
  && ((auth_file && streq (auth_file, "management")) || (from_stdin && (flags & GET_USER_PASS_MANAGEMENT)))
  && management_query_user_pass_enabled (management))
{
  if (!management_query_user_pass (management, up, prefix, flags))
    {
      if ((flags & GET_USER_PASS_NOFATAL) != 0)
return false;
      else
msg (M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
    }
}
      else
#endif
      /*
       * Get NEED_OK confirmation from the console
       */
      if (flags & GET_USER_PASS_NEED_OK)
{
  struct buffer user_prompt = alloc_buf_gc (128, &gc);   buf_printf (&user_prompt, "NEED-OK|%s|%s:", prefix, up->username);
  
  if (!get_console_input (BSTR (&user_prompt), true, up->password, USER_PASS_LEN))
    msg (M_FATAL, "ERROR: could not read %s ok-confirmation from stdin", prefix);
  
  if (!strlen (up->password))
    strcpy (up->password, "ok");
}
  
      /*
       * Get username/password from standard input?
       */
      else if (from_stdin)
{
  struct buffer user_prompt = alloc_buf_gc (128, &gc);
  struct buffer pass_prompt = alloc_buf_gc (128, &gc);   buf_printf (&user_prompt, "Enter %s Username:", prefix);
  buf_printf (&pass_prompt, "Enter %s Password:", prefix);   if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
    {
      if (!get_console_input (BSTR (&user_prompt), true, up->username, USER_PASS_LEN))
msg (M_FATAL, "ERROR: could not read %s username from stdin", prefix);
      if (strlen (up->username) == 0)
msg (M_FATAL, "ERROR: %s username is empty", prefix);
    }   if (!get_console_input (BSTR (&pass_prompt), false, up->password, USER_PASS_LEN))
    msg (M_FATAL, "ERROR: could not not read %s password from stdin", prefix);
}
      else
{
  /*
   * Get username/password from a file.
   */
  FILE *fp;#ifndef ENABLE_PASSWORD_SAVE
  /*
   * Unless ENABLE_PASSWORD_SAVE is defined, don't allow sensitive passwords
   * to be read from a file.
   */
   
  if (flags & GET_USER_PASS_SENSITIVE)
    msg (M_FATAL, "Sorry, '%s' password cannot be read from a file", prefix);
#endif   warn_if_group_others_accessible (auth_file);   fp = fopen (auth_file, "r");
  if (!fp)
    msg (M_ERR, "Error opening '%s' auth file: %s", prefix, auth_file);   if (flags & GET_USER_PASS_PASSWORD_ONLY)
    {
      if (fgets (up->password, USER_PASS_LEN, fp) == NULL)
msg (M_FATAL, "Error reading password from %s authfile: %s",
     prefix,
     auth_file);
    }
  else
    {
      if (fgets (up->username, USER_PASS_LEN, fp) == NULL
  || fgets (up->password, USER_PASS_LEN, fp) == NULL)
msg (M_FATAL, "Error reading username and password (must be on two consecutive lines) from %s authfile: %s",
     prefix,
     auth_file);
    }
      
  fclose (fp);
      
  chomp (up->username);
  chomp (up->password);
      
  if (!(flags & GET_USER_PASS_PASSWORD_ONLY) && strlen (up->username) == 0)
    msg (M_FATAL, "ERROR: username from %s authfile '%s' is empty", prefix, auth_file);
}      string_mod (up->username, CC_PRINT, CC_CRLF, 0);
      string_mod (up->password, CC_PRINT, CC_CRLF, 0);      up->defined = true;
    }#if 0
  msg (M_INFO, "GET_USER_PASS %s u='%s' p='%s'", prefix, up->username, up->password);
#endif  gc_free (&gc);  return true;
}#if AUTO_USERIDstatic const char *
get_platform_prefix (void)
{
#if defined(TARGET_LINUX)
  return "L";
#elif defined(TARGET_SOLARIS)
  return "S";
#elif defined(TARGET_OPENBSD)
  return "O";
#elif defined(TARGET_DARWIN)
  return "M";
#elif defined(TARGET_NETBSD)
  return "N";
#elif defined(TARGET_FREEBSD)
  return "F";
#elif defined(WIN32)
  return "W";
#else
  return "X";
#endif
}void
get_user_pass_auto_userid (struct user_pass *up, const char *tag)
{
  struct gc_arena gc = gc_new ();
  MD5_CTX ctx;
  struct buffer buf;
  uint8_t macaddr[6];
  static uint8_t digest [MD5_DIGEST_LENGTH];
  static const uint8_t hashprefix[] = "AUTO_USERID_DIGEST";  CLEAR (*up);
  buf_set_write (&buf, (uint8_t*)up->username, USER_PASS_LEN);
  buf_printf (&buf, "%s", get_platform_prefix ());
  if (get_default_gateway_mac_addr (macaddr))
    {
      dmsg (D_AUTO_USERID, "GUPAU: macaddr=%s", format_hex_ex (macaddr, sizeof (macaddr), 0, 1, ":", &gc));
      MD5_Init (&ctx);
      MD5_Update (&ctx, hashprefix, sizeof (hashprefix) - 1);
      MD5_Update (&ctx, macaddr, sizeof (macaddr));
      MD5_Final (digest, &ctx);
      buf_printf (&buf, "%s", format_hex_ex (digest, sizeof (digest), 0, 256, " ", &gc));
    }
  else
    {
      buf_printf (&buf, "UNKNOWN");
    }
  if (tag && strcmp (tag, "stdin"))
    buf_printf (&buf, "-%s", tag);
  up->defined = true;
  gc_free (&gc);  dmsg (D_AUTO_USERID, "GUPAU: AUTO_USERID: '%s'", up->username);
}#endifvoid
purge_user_pass (struct user_pass *up, const bool force)
{
  const bool nocache = up->nocache;
  if (nocache || force)
    {
      CLEAR (*up);
      up->nocache = nocache;
    }
  else
    {
      msg (M_WARN, "WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this");
    }
}
有兴趣的可以去看看。。源码下载地址http://openvpn.net/release/openvpn-2.1.1.tar.gz
解决了的! 再送上100分