/[winpt]/trunk/Src/wptKeyserver.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeyserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 119 by twoaday, Fri Dec 9 08:04:51 2005 UTC revision 133 by twoaday, Mon Jan 9 09:15:29 2006 UTC
# Line 1122  proxy_release( keyserver_proxy_ctx *ctx Line 1122  proxy_release( keyserver_proxy_ctx *ctx
1122  }  }
1123    
1124    
1125    /* Spawn a process given by @cmdl. */
1126    static int
1127    spawn_application (char *cmdl)
1128    {
1129        STARTUPINFO si;
1130        PROCESS_INFORMATION pi;
1131        int rc = 0;
1132    
1133        memset (&si, 0, sizeof (si));
1134        si.cb = sizeof (si);
1135        si.dwFlags = STARTF_USESHOWWINDOW;
1136        si.wShowWindow = SW_HIDE;
1137        memset (&pi, 0, sizeof (pi));
1138    
1139        if (!CreateProcess (NULL, cmdl, NULL, NULL, FALSE, 0,
1140                            NULL, NULL, &si, &pi)) {
1141            log_box ("Keyserver Plugin", MB_ERR, "Could not spawn helper process");
1142            rc = -1;
1143        }
1144    
1145        CloseHandle (pi.hThread);
1146        WaitForSingleObject (pi.hProcess, INFINITE);
1147        CloseHandle (pi.hProcess);
1148        return rc;
1149    }
1150    
1151    
1152  /* Receive an key via LDAP from host @host with the keyid @keyid.  /* Receive an key via LDAP from host @host with the keyid @keyid.
1153     @key contains the key on success. */     @key contains the key on success. */
1154  int  int
1155  ldap_recvkey (const char *host, const char *keyid, char *key, int maxkeylen)  ldap_recvkey (const char *host, const char *keyid, char *key, int maxkeylen)
1156  {  {    
1157        FILE *inp;
1158        DWORD n;
1159      const char *s;      const char *s;
1160      char *ksprg = NULL, *p = NULL;      char *ksprg = NULL, *p = NULL, *sep;
1161      char temp[512], outf[512];      char temp[512], outf[512];
1162      FILE * inp;      int start_key = 0, failed = 0;
1163      int rc, start_key = 0;      int rc = 0;
     STARTUPINFO si;  
     PROCESS_INFORMATION pi;  
1164    
1165      p = get_gnupg_path ();      p = get_gnupg_prog ();
1166      ksprg = new char[strlen (p) + 1 + 128];      n = strlen (p) + 1 + 128;
1167        ksprg = new char[n+1];
1168      if (!ksprg)      if (!ksprg)
1169          BUG (0);          BUG (0);
1170      strcpy (ksprg, p);      sep = strrchr (p, '\\');
1171      strcat (ksprg, "\\");      if (sep != NULL)
1172      strcat (ksprg, "gpgkeys_ldap.exe");          p[(sep-p)] = 0;
1173    
1174        _snprintf (ksprg, n, "%s\\gpgkeys_ldap.exe", p);
1175      free_if_alloc (p);      free_if_alloc (p);
1176      if (file_exist_check (ksprg)) {      if (file_exist_check (ksprg)) {
1177          log_box ( "LDAP Keyserver Plugin", MB_ERR, "Could not find LDAP keyserver module!");          log_box ("LDAP Keyserver Plugin", MB_ERR,
1178          rc = -1;                   "%s: could not find LDAP keyserver module!", ksprg);
1179            rc = -1;
1180          goto leave;          goto leave;
1181      }      }    
1182      GetTempPath (sizeof (temp)-1, temp);      GetTempPath (sizeof (temp)-1, temp);
1183      strcpy (outf, temp);      _snprintf (outf, sizeof (outf)-1, "%s%s.out", temp, keyid);
     strcat (outf, keyid);  
     strcat (outf, ".out");  
1184      strcat (temp, keyid);      strcat (temp, keyid);
1185      inp = fopen (temp, "w+b");      inp = fopen (temp, "w+b");
1186      if( !inp ) {      if (!inp) {
1187          log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", temp,          log_box ("LDAP Keyserver Plugin", MB_ERR, "%s: %s", temp,
1188                   winpt_strerror (WPTERR_FILE_OPEN));                   winpt_strerror (WPTERR_FILE_OPEN));
1189          rc = -1;          rc = -1;
1190          goto leave;          goto leave;
1191      }      }
1192      fprintf (inp,      fprintf (inp,
1193          "VERSION 0\n"          "VERSION 1\n"
1194            "PROGRAM 1.4.3-cvs\n"
1195            "SCHEME ldap\n"
1196          "HOST %s\n"          "HOST %s\n"
         "OPTION verbose\n"  
1197          "COMMAND GET\n"          "COMMAND GET\n"
1198          "\n"          "\n"
1199          "%s\n", host? skip_type_prefix (host): "64.94.85.200", keyid);          "%s\n",
1200            host? skip_type_prefix (host): "64.94.85.200", keyid);
1201      fclose (inp);      fclose (inp);
1202    
     memset (&si, 0, sizeof (si));  
     si.cb = sizeof (si);  
     si.dwFlags = STARTF_USESHOWWINDOW;  
     si.wShowWindow = SW_HIDE;  
     memset (&pi, 0, sizeof (pi));  
1203      p = new char[strlen (ksprg) + strlen (temp) + strlen (outf) + 32];      p = new char[strlen (ksprg) + strlen (temp) + strlen (outf) + 32];
1204        if (!p)
1205            BUG (NULL);
1206      sprintf (p, "%s -o %s %s", ksprg, outf, temp);      sprintf (p, "%s -o %s %s", ksprg, outf, temp);
1207      rc = CreateProcess (NULL, p, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);      if (spawn_application (p)) {
     if (!rc) {  
         log_box ("LDAP Keyserver Plugin", MB_ERR, "Could not spawn process");  
1208          rc = -1;          rc = -1;
1209          goto leave;          goto leave;
1210      }      }
1211      CloseHandle (pi.hThread);      DeleteFile (temp);
     WaitForSingleObject (pi.hProcess, INFINITE);  
     CloseHandle (pi.hProcess);  
1212    
1213      inp = fopen (outf, "rb");      inp = fopen (outf, "rb");
1214      if (!inp) {      if (!inp) {
# Line 1194  ldap_recvkey (const char *host, const ch Line 1218  ldap_recvkey (const char *host, const ch
1218          goto leave;          goto leave;
1219      }      }
1220      memset (key, 0, maxkeylen);      memset (key, 0, maxkeylen);
1221      while( !feof( inp ) ) {      while (!feof (inp)) {
1222          s = fgets( temp, sizeof (temp)-1, inp );          s = fgets (temp, sizeof (temp)-1, inp);
1223          if( !s )          if (!s)
1224                break;
1225            if (strstr (s, "KEY") && strstr (s, "FAILED")) {
1226                failed = 1;
1227              break;              break;
1228          if( !start_key && strstr( s, "KEY" ) && strstr( s, "BEGIN" ) ) {          }
1229            if (!start_key && strstr (s, "KEY") && strstr (s, "BEGIN")) {
1230              start_key = 1;              start_key = 1;
1231              continue;              continue;
1232          }                }      
1233          if( !start_key )          if (!start_key)
1234              continue;              continue;
1235          strcat( key, temp );          strcat (key, temp);
1236          maxkeylen -= strlen( temp );          maxkeylen -= strlen (temp);
1237          if( maxkeylen < 0 || (strstr( s, "KEY" ) && strstr( s, "END" )) )                    if (maxkeylen < 0 || (strstr (s, "KEY") && strstr (s, "END")))
1238              break;              break;
1239      }      }
1240      fclose( inp );          fclose (inp);
1241    
1242  leave:  leave:
1243      if( !strlen( key ) )      if (failed || !strlen (key))
1244          rc = WPTERR_WINSOCK_RECVKEY;          rc = WPTERR_WINSOCK_RECVKEY;
1245      free_if_alloc( p );      DeleteFile (outf);
1246      free_if_alloc( ksprg );      free_if_alloc (p);
1247        free_if_alloc (ksprg);
1248      return rc;      return rc;
1249  }  }
1250    

Legend:
Removed from v.119  
changed lines
  Added in v.133

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26