• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

libkpgp

kpgpbase.cpp

Go to the documentation of this file.
00001 /*
00002     kpgpbase.cpp
00003 
00004     Copyright (C) 2001,2002 the KPGP authors
00005     See file AUTHORS.kpgp for details
00006 
00007     This file is part of KPGP, the KDE PGP/GnuPG support library.
00008 
00009     KPGP is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software Foundation,
00016     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include <config-libkpgp.h> /* HAVE_SYS_POLL_H */
00020 
00021 #include "kpgpbase.h"
00022 #include "kpgp.h"
00023 #include "kpgpblock.h"
00024 
00025 #include <kdebug.h>
00026 #include <kdefakes.h> /* setenv, unsetenv */
00027 
00028 #include <QApplication>
00029 #include <QByteArray>
00030 
00031 #include <stdlib.h> /* setenv, unsetenv */
00032 #include <unistd.h> /* pipe, close, fork, dup2, execl, _exit, write, read */
00033 #include <errno.h>
00034 
00035 #ifdef HAVE_SYS_POLL_H
00036 #include <sys/poll.h>  /* poll, etc. */
00037 #endif
00038 
00039 #include <sys/types.h> /* pid_t */
00040 #include <sys/wait.h> /* waitpid */
00041 
00042 namespace Kpgp {
00043 
00044 Base::Base()
00045   : input(), output(), error(), errMsg(), status(OK)
00046 {
00047 }
00048 
00049 
00050 Base::~Base()
00051 {
00052 }
00053 
00054 
00055 void
00056 Base::clear()
00057 {
00058   input = QByteArray();
00059   output = QByteArray();
00060   error = QByteArray();
00061   errMsg.clear();
00062   status = OK;
00063 }
00064 
00065 
00066 int
00067 Base::run( const char *cmd, const char *passphrase, bool onlyReadFromPGP )
00068 {
00069 #ifdef HAVE_SYS_POLL_H
00070   /* the pipe ppass is used for to pass the password to
00071    * pgp. passing the password together with the normal input through
00072    * stdin doesn't seem to work as expected (at least for pgp5.0)
00073    */
00074   char str[1025] = "\0";
00075   int pin[2], pout[2], perr[2], ppass[2];
00076   int len, len2;
00077   FILE *pass;
00078   pid_t child_pid;
00079   int childExitStatus;
00080   struct pollfd pollin, pollout, pollerr;
00081   int pollstatus;
00082 
00083   if(passphrase)
00084   {
00085     pipe(ppass);
00086 
00087     pass = fdopen(ppass[1], "w");
00088     fwrite(passphrase, sizeof(char), strlen(passphrase), pass);
00089     fwrite("\n", sizeof(char), 1, pass);
00090     fclose(pass);
00091     close(ppass[1]);
00092 
00093     // tell pgp which fd to use for the passphrase
00094     QString tmp;
00095     tmp.sprintf("%d",ppass[0]);
00096     ::setenv("PGPPASSFD",tmp.toUtf8()/*.data()*/,1);
00097 
00098     //Uncomment these lines for testing only! Doing so will decrease security!
00099     //kDebug( 5326 ) <<"pgp PGPPASSFD =" << tmp;
00100     //kDebug( 5326 ) <<"pgp pass =" << passphrase;
00101   }
00102   else
00103     ::unsetenv("PGPPASSFD");
00104 
00105   //Uncomment these lines for testing only! Doing so will decrease security!
00106   kDebug( 5326 ) <<"pgp cmd =" << cmd;
00107   //kDebug( 5326 ) <<"pgp input =" << QString(input)
00108   //          << "input length =" << input.length();
00109 
00110   error = "";
00111   output = "";
00112 
00113   pipe(pin);
00114   pipe(pout);
00115   pipe(perr);
00116 
00117   QApplication::flush();
00118   if(!(child_pid = fork()))
00119   {
00120     /*We're the child.*/
00121     close(pin[1]);
00122     dup2(pin[0], 0);
00123     close(pin[0]);
00124 
00125     close(pout[0]);
00126     dup2(pout[1], 1);
00127     close(pout[1]);
00128 
00129     close(perr[0]);
00130     dup2(perr[1], 2);
00131     close(perr[1]);
00132 
00133     execl("/bin/sh", "sh", "-c", cmd,  (void *)0);
00134     _exit(127);
00135   }
00136 
00137   /*Only get here if we're the parent.*/
00138   close(pin[0]);
00139   close(pout[1]);
00140   close(perr[1]);
00141 
00142   // poll for "There is data to read."
00143   pollout.fd = pout[0];
00144   pollout.events = POLLIN;
00145   pollout.revents = 0; // init with 0, just in case
00146   pollerr.fd = perr[0];
00147   pollerr.events = POLLIN;
00148   pollerr.revents = 0; // init with 0, just in case
00149 
00150   // poll for "Writing now will not block."
00151   pollin.fd = pin[1];
00152   pollin.events = POLLOUT;
00153   pollin.revents = 0; // init with 0, just in case
00154 
00155   if (!onlyReadFromPGP) {
00156     if (!input.isEmpty()) {
00157       // write to pin[1] one line after the other to prevent dead lock
00158       for (int i=0; i<input.length(); i+=len2) {
00159         len2 = 0;
00160 
00161         // check if writing now to pin[1] will not block (5 ms timeout)
00162         //kDebug( 5326 ) <<"Polling pin[1]...";
00163         pollstatus = poll(&pollin, 1, 5);
00164         if (pollstatus == 1) {
00165           //kDebug( 5326 ) <<"Status for polling pin[1]:" << pollin.revents;
00166           if (pollin.revents & POLLERR) {
00167             kDebug( 5326 ) <<"PGP seems to have hung up";
00168             break;
00169           }
00170           else if (pollin.revents & POLLOUT) {
00171             // search end of next line
00172             if ((len2 = input.indexOf('\n', i)) == -1)
00173               len2 = input.length()-i;
00174             else
00175               len2 = len2-i+1;
00176 
00177             //kDebug( 5326 ) <<"Trying to write" << len2 <<" bytes to pin[1] ...";
00178             len2 = write(pin[1], input.mid(i,len2).data(), len2);
00179             //kDebug( 5326 ) <<"Wrote" << len2 <<" bytes to pin[1] ...";
00180           }
00181         }
00182         else if (!pollstatus) {
00183           //kDebug( 5326 ) <<"Timeout while polling pin[1]:"
00184           //              << pollin.revents;
00185         }
00186         else if (pollstatus == -1) {
00187           kDebug( 5326 ) <<"Error while polling pin[1]:"
00188                         << pollin.revents;
00189         }
00190 
00191         if (pout[0] >= 0) {
00192           do {
00193             // check if there is data to read from pout[0]
00194             //kDebug( 5326 ) <<"Polling pout[0]...";
00195             pollstatus = poll(&pollout, 1, 0);
00196             if (pollstatus == 1) {
00197               //kDebug( 5326 ) <<"Status for polling pout[0]:" << pollout.revents;
00198               if (pollout.revents & POLLIN) {
00199                 //kDebug( 5326 ) <<"Trying to read" << 1024 <<" bytes from pout[0]";
00200                 if ((len = read(pout[0],str,1024))>0) {
00201                   //kDebug( 5326 ) <<"Read" << len <<" bytes from pout[0]";
00202                   str[len] ='\0';
00203                   output += str;
00204                 }
00205                 else
00206                   break;
00207               }
00208             }
00209             else if (pollstatus == -1) {
00210               kDebug( 5326 ) <<"Error while polling pout[0]:"
00211                             << pollout.revents;
00212             }
00213           } while ((pollstatus == 1) && (pollout.revents & POLLIN));
00214         }
00215 
00216         if (perr[0] >= 0) {
00217           do {
00218             // check if there is data to read from perr[0]
00219             //kDebug( 5326 ) <<"Polling perr[0]...";
00220             pollstatus = poll(&pollerr, 1, 0);
00221             if (pollstatus == 1) {
00222               //kDebug( 5326 ) <<"Status for polling perr[0]:" << pollerr.revents;
00223               if (pollerr.revents & POLLIN) {
00224                 //kDebug( 5326 ) <<"Trying to read" << 1024 <<" bytes from perr[0]";
00225                 if ((len = read(perr[0],str,1024))>0) {
00226                   //kDebug( 5326 ) <<"Read" << len <<" bytes from perr[0]";
00227                   str[len] ='\0';
00228                   error += str;
00229                 }
00230                 else
00231                   break;
00232               }
00233             }
00234             else if (pollstatus == -1) {
00235               kDebug( 5326 ) <<"Error while polling perr[0]:"
00236                             << pollerr.revents;
00237             }
00238           } while ((pollstatus == 1) && (pollerr.revents & POLLIN));
00239         }
00240 
00241         // abort writing to PGP if PGP hung up
00242         if ((pollstatus == 1) &&
00243             ((pollout.revents & POLLHUP) || (pollerr.revents & POLLHUP))) {
00244           kDebug( 5326 ) <<"PGP hung up";
00245           break;
00246         }
00247       }
00248     }
00249     else // if input.isEmpty()
00250       write(pin[1], "\n", 1);
00251     //kDebug( 5326 ) <<"All input was written to pin[1]";
00252   }
00253   close(pin[1]);
00254 
00255   pid_t waitpidRetVal;
00256 
00257   do {
00258     //kDebug( 5326 ) <<"Checking if PGP is still running...";
00259     childExitStatus = 0;
00260     waitpidRetVal = waitpid(child_pid, &childExitStatus, WNOHANG);
00261     //kDebug( 5326 ) <<"waitpid returned" << waitpidRetVal;
00262     if (pout[0] >= 0) {
00263       do {
00264         // check if there is data to read from pout[0]
00265         //kDebug( 5326 ) <<"Polling pout[0]...";
00266         pollstatus = poll(&pollout, 1, 0);
00267         if (pollstatus == 1) {
00268           //kDebug( 5326 ) <<"Status for polling pout[0]:" << pollout.revents;
00269           if (pollout.revents & POLLIN) {
00270             //kDebug( 5326 ) <<"Trying to read" << 1024 <<" bytes from pout[0]";
00271             if ((len = read(pout[0],str,1024))>0) {
00272               //kDebug( 5326 ) <<"Read" << len <<" bytes from pout[0]";
00273               str[len] ='\0';
00274               output += str;
00275             } else {
00276               /*
00277                * Apparently, on NetBSD when the child dies, the pipe begins
00278                * receiving empty data packets *before* waitpid() has signaled
00279                * that the child has died.  Also, notice that this happens
00280                * without any error bit being set in pollfd.revents (is this a
00281                * NetBSD bug??? ).  Notice that these anomalous packets exist
00282                * according to poll(), but have length 0 according to read().
00283                * Thus, kde can remain stuck inside this loop.
00284                *
00285                * A solution to this problem is to get out of the inner loop
00286                * when read() returns <=0.  In this way, kde has another chance
00287                * to call waitpid() to check if the child has died -- and this
00288                * time the call should succeed.
00289                *
00290                * Setting POLLHUP in pollfd.revents is not necessary, but I just
00291                * like the idea of signaling that something strange has
00292                * happened.
00293                */
00294               pollout.revents |= POLLHUP;
00295               break;
00296             }
00297           }
00298         }
00299         else if (pollstatus == -1) {
00300           kDebug( 5326 ) <<"Error while polling pout[0]:"
00301                         << pollout.revents;
00302         }
00303       } while ((pollstatus == 1) && (pollout.revents & POLLIN));
00304     }
00305 
00306     if (perr[0] >= 0) {
00307       do {
00308         // check if there is data to read from perr[0]
00309         //kDebug( 5326 ) <<"Polling perr[0]...";
00310         pollstatus = poll(&pollerr, 1, 0);
00311         if (pollstatus == 1) {
00312           //kDebug( 5326 ) <<"Status for polling perr[0]:" << pollerr.revents;
00313           if (pollerr.revents & POLLIN) {
00314             //kDebug( 5326 ) <<"Trying to read" << 1024 <<" bytes from perr[0]";
00315             if ((len = read(perr[0],str,1024))>0) {
00316               //kDebug( 5326 ) <<"Read" << len <<" bytes from perr[0]";
00317               str[len] ='\0';
00318               error += str;
00319             } else {
00320               /*
00321                * Apparently, on NetBSD when the child dies, the pipe begins
00322                * receiving empty data packets *before* waitpid() has signaled
00323                * that the child has died.  Also, notice that this happens
00324                * without any error bit being set in pollfd.revents (is this a
00325                * NetBSD bug??? ).  Notice that these anomalous packets exist
00326                * according to poll(), but have length 0 according to read().
00327                * Thus, kde can remain stuck inside this loop.
00328                *
00329                * A solution to this problem is to get out of the inner loop
00330                * when read() returns <=0.  In this way, kde has another chance
00331                * to call waitpid() to check if the child has died -- and this
00332                * time the call should succeed.
00333                *
00334                * Setting POLLHUP in pollfd.revents is not necessary, but I just
00335                * like the idea of signaling that something strange has
00336                * happened.
00337                */
00338               pollerr.revents |= POLLHUP;
00339               break;
00340             }
00341           }
00342         }
00343         else if (pollstatus == -1) {
00344           kDebug( 5326 ) <<"Error while polling perr[0]:"
00345                         << pollerr.revents;
00346         }
00347       } while ((pollstatus == 1) && (pollerr.revents & POLLIN));
00348     }
00349   } while (waitpidRetVal == 0);
00350 
00351   close(pout[0]);
00352   close(perr[0]);
00353 
00354   unsetenv("PGPPASSFD");
00355   if(passphrase)
00356     close(ppass[0]);
00357 
00358   // Did the child exit normally?
00359   if (WIFEXITED(childExitStatus) != 0) {
00360     // Get the return code of the child
00361     childExitStatus = WEXITSTATUS(childExitStatus);
00362     kDebug( 5326 ) <<"PGP exited with exit status" << childExitStatus;
00363   }
00364   else {
00365     childExitStatus = -1;
00366     kDebug( 5326 ) <<"PGP exited abnormally!";
00367   }
00368 
00369   //Uncomment these lines for testing only! Doing so will decrease security!
00370   //kDebug( 5326 ) <<"pgp output =" << QString(output);
00371   //kDebug( 5326 ) <<"pgp error =" << error;
00372 
00373   /* Make the information visible, so that a user can
00374    * get to know what's going on during the pgp calls.
00375    */
00376   kDebug( 5326 ) << error;
00377 
00378   return childExitStatus;
00379 #else // HAVE_SYS_POLL_H
00380 #ifdef __GNUC__
00381 #warning WIN32 libkpgp: PGP support not ported to win32!
00382 #endif
00383   return 1;
00384 #endif
00385 }
00386 
00387 
00388 int
00389 Base::runGpg( const char *cmd, const char *passphrase, bool onlyReadFromGnuPG )
00390 {
00391 #ifdef HAVE_SYS_POLL_H
00392   /* the pipe ppass is used for to pass the password to
00393    * pgp. passing the password together with the normal input through
00394    * stdin doesn't seem to work as expected (at least for pgp5.0)
00395    */
00396   char str[1025] = "\0";
00397   int pin[2], pout[2], perr[2], ppass[2];
00398   int len, len2;
00399   FILE *pass;
00400   pid_t child_pid;
00401   int childExitStatus;
00402   char gpgcmd[1024] = "\0";
00403   struct pollfd poller[3];
00404   int num_pollers = 0;
00405   const int STD_OUT = 0;
00406   const int STD_ERR = 1;
00407   const int STD_IN = 2;
00408   int pollstatus;
00409 
00410   if(passphrase)
00411   {
00412     pipe(ppass);
00413 
00414     pass = fdopen(ppass[1], "w");
00415     fwrite(passphrase, sizeof(char), strlen(passphrase), pass);
00416     fwrite("\n", sizeof(char), 1, pass);
00417     fclose(pass);
00418     close(ppass[1]);
00419 
00420     //Uncomment these lines for testing only! Doing so will decrease security!
00421     //kDebug( 5326 ) <<"pass =" << passphrase;
00422   }
00423 
00424   //Uncomment these lines for testing only! Doing so will decrease security!
00425   //kDebug( 5326 ) <<"pgp cmd =" << cmd;
00426   //kDebug( 5326 ) <<"pgp input =" << QString(input)
00427   //          << "input length =" << input.length();
00428 
00429   error = "";
00430   output = "";
00431 
00432   pipe(pin);
00433   pipe(pout);
00434   pipe(perr);
00435 
00436   if( passphrase ) {
00437     if( mVersion >= "1.0.7" ) {
00438       // GnuPG >= 1.0.7 supports the gpg-agent, so we look for it.
00439       if( 0 == getenv("GPG_AGENT_INFO") ) {
00440         // gpg-agent not found, so we tell gpg not to use the agent
00441         snprintf( gpgcmd, 1023,
00442                   "LANGUAGE=C gpg --no-use-agent --passphrase-fd %d %s",
00443                   ppass[0], cmd );
00444       }
00445       else {
00446         // gpg-agent seems to be running, so we tell gpg to use the agent
00447         snprintf( gpgcmd, 1023,
00448                   "LANGUAGE=C gpg --use-agent %s",
00449                   cmd );
00450       }
00451     }
00452     else {
00453       // GnuPG < 1.0.7 doesn't know anything about the gpg-agent
00454       snprintf( gpgcmd, 1023,
00455                 "LANGUAGE=C gpg --passphrase-fd %d %s",
00456                 ppass[0], cmd );
00457     }
00458   }
00459   else {
00460     snprintf(gpgcmd, 1023, "LANGUAGE=C gpg %s",cmd);
00461   }
00462 
00463   QApplication::flush();
00464   if(!(child_pid = fork()))
00465   {
00466     /*We're the child.*/
00467     close(pin[1]);
00468     dup2(pin[0], 0);
00469     close(pin[0]);
00470 
00471     close(pout[0]);
00472     dup2(pout[1], 1);
00473     close(pout[1]);
00474 
00475     close(perr[0]);
00476     dup2(perr[1], 2);
00477     close(perr[1]);
00478 
00479     //#warning FIXME: there has to be a better way to do this
00480      /* this is nasty nasty nasty (but it works) */
00481     if( passphrase ) {
00482       if( mVersion >= "1.0.7" ) {
00483         // GnuPG >= 1.0.7 supports the gpg-agent, so we look for it.
00484         if( 0 == getenv("GPG_AGENT_INFO") ) {
00485           // gpg-agent not found, so we tell gpg not to use the agent
00486           snprintf( gpgcmd, 1023,
00487                     "LANGUAGE=C gpg --no-use-agent --passphrase-fd %d %s",
00488                     ppass[0], cmd );
00489         }
00490         else {
00491           // gpg-agent seems to be running, so we tell gpg to use the agent
00492           snprintf( gpgcmd, 1023,
00493                     "LANGUAGE=C gpg --use-agent %s",
00494                     cmd );
00495         }
00496       }
00497       else {
00498         // GnuPG < 1.0.7 doesn't know anything about the gpg-agent
00499         snprintf( gpgcmd, 1023,
00500                   "LANGUAGE=C gpg --passphrase-fd %d %s",
00501                   ppass[0], cmd );
00502       }
00503     }
00504     else {
00505       snprintf(gpgcmd, 1023, "LANGUAGE=C gpg %s",cmd);
00506     }
00507 
00508     kDebug( 5326 ) <<"pgp cmd =" << gpgcmd;
00509 
00510     execl("/bin/sh", "sh", "-c", gpgcmd,  (void *)0);
00511     _exit(127);
00512   }
00513 
00514   // Only get here if we're the parent.
00515 
00516   close(pin[0]);
00517   close(pout[1]);
00518   close(perr[1]);
00519 
00520   // poll for "There is data to read."
00521   poller[STD_OUT].fd = pout[0];
00522   poller[STD_OUT].events = POLLIN;
00523   poller[STD_ERR].fd = perr[0];
00524   poller[STD_ERR].events = POLLIN;
00525   num_pollers = 2;
00526 
00527   if (!onlyReadFromGnuPG) {
00528     // poll for "Writing now will not block."
00529     poller[STD_IN].fd = pin[1];
00530     poller[STD_IN].events = POLLOUT;
00531     num_pollers = 3;
00532   } else {
00533     close (pin[1]);
00534     pin[1] = -1;
00535   }
00536 
00537   pid_t waitpidRetVal;
00538   int input_pos = 0;
00539 
00540   do {
00541     //kDebug( 5326 ) <<"Checking if GnuPG is still running...";
00542     childExitStatus = 0;
00543     waitpidRetVal = waitpid(child_pid, &childExitStatus, WNOHANG);
00544     //kDebug( 5326 ) <<"waitpid returned" << waitpidRetVal;
00545     do {
00546       // poll the pipes
00547       pollstatus = poll(poller, num_pollers, 10);
00548       if( 0 < pollstatus ) {
00549         // Check stdout.
00550         if (poller[STD_OUT].revents & POLLIN) {
00551           //kDebug( 5326 ) <<"Trying to read" << 1024 <<" bytes from pout[0]";
00552           if ((len = read(pout[0],str,1024))>0) {
00553             //kDebug( 5326 ) <<"Read" << len <<" bytes from pout[0]";
00554             str[len] ='\0';
00555             output += str;
00556           }
00557           else {
00558             // FreeBSD/NetBSD workaround
00559             //
00560             // Apparently, on Free/NetBSD when the child dies, the pipe begins
00561             // receiving empty data packets *before* waitpid() has signaled
00562             // that the child has died.  Also, notice that this happens
00563             // without any error bit being set in pollfd.revents (is this a
00564             // Free/NetBSD bug??? ).  Notice that these anomalous packets exist
00565             // according to poll(), but have length 0 according to read().
00566             // Thus, we can remain stuck inside this loop.
00567             //
00568             // A solution to this problem is to get out of the inner loop
00569             // when read() returns <=0.  In this way, we have another chance
00570             // to call waitpid() to check if the child has died -- and this
00571             // time the call should succeed.
00572             //
00573             // Set POLLHUP in pollfd.revents to signal that something strange
00574             // has happened and disable polling of stdout.
00575             poller[STD_OUT].revents |= POLLHUP;
00576             poller[STD_OUT].events = 0;
00577           }
00578         } else if (poller[STD_OUT].revents & POLLHUP) {
00579           // disable polling of stdout
00580           poller[STD_OUT].events = 0;
00581         }
00582 
00583         // Check stderr.
00584         if (poller[STD_ERR].revents & POLLIN) {
00585           //kDebug( 5326 ) <<"Trying to read" << 1024 <<" bytes from perr[0]";
00586           if ((len = read(poller[STD_ERR].fd,str,1024))>0) {
00587             //kDebug( 5326 ) <<"Read" << len <<" bytes from perr[0]";
00588             str[len] ='\0';
00589             error += str;
00590           }
00591           else {
00592             // FreeBSD/NetBSD workaround (for details see above)
00593             poller[STD_ERR].revents |= POLLHUP;
00594             poller[STD_ERR].events = 0;
00595           }
00596         } else if (poller[STD_ERR].revents & POLLHUP) {
00597           // disable polling of stderr
00598           poller[STD_ERR].events = 0;
00599         }
00600 
00601         if (num_pollers > 2) {
00602           if (poller[STD_IN].revents & ( POLLERR | POLLHUP ) ) {
00603             kDebug( 5326 ) <<"GnuPG seems to have hung up";
00604             close (pin[1]);
00605             pin[1] = -1;
00606             --num_pollers;
00607           }
00608           else if (poller[STD_IN].revents & POLLOUT) {
00609             if (!input.isEmpty()) {
00610               // search end of next line
00611               if ((len2 = input.indexOf('\n', input_pos)) == -1)
00612                 len2 = input.length()-input_pos;
00613               else
00614                 len2 = len2-input_pos+1;
00615 
00616               //kDebug( 5326 ) <<"Trying to write" << len2 <<" bytes to pin[1] ...";
00617               len2 = write(pin[1], input.mid(input_pos,len2).data(), len2);
00618               //kDebug( 5326 ) <<"Wrote" << len2 <<" bytes to pin[1] ...";
00619               input_pos += len2;
00620 
00621               // We are done.
00622               if (input_pos >= input.length()) {
00623                 //kDebug( 5326 ) <<"All input was written to pin[1]";
00624                 close (pin[1]);
00625                 pin[1] = -1;
00626                 --num_pollers;
00627               }
00628             }
00629             else { // if input.isEmpty()
00630               write(pin[1], "\n", 1);
00631               //kDebug( 5326 ) <<"All input was written to pin[1]";
00632               close (pin[1]);
00633               pin[1] = -1;
00634               --num_pollers;
00635             }
00636           }
00637         }
00638       }
00639     } while ( (pollstatus > 0) && ( (num_pollers > 2)
00640                                     || (poller[STD_OUT].events != 0)
00641                                     || (poller[STD_ERR].events != 0) ) );
00642 
00643     if (pollstatus == -1) {
00644       kDebug( 5326 ) <<"GnuPG poll failed, errno:" << errno;
00645     }
00646 
00647   } while(waitpidRetVal == 0);
00648 
00649   if( 0 <= pin[1] )
00650     close (pin[1]);
00651   close(pout[0]);
00652   close(perr[0]);
00653 
00654   if(passphrase)
00655     close(ppass[0]);
00656 
00657   // Did the child exit normally?
00658   if (WIFEXITED(childExitStatus) != 0) {
00659     // Get the return code of the child
00660     childExitStatus = WEXITSTATUS(childExitStatus);
00661     kDebug( 5326 ) <<"GnuPG exited with exit status" << childExitStatus;
00662   }
00663   else {
00664     childExitStatus = -1;
00665     kDebug( 5326 ) <<"GnuPG exited abnormally!";
00666   }
00667 
00668   //Uncomment these lines for testing only! Doing so will decrease security!
00669   //kDebug( 5326 ) <<"gpg stdout:" << QString(output);
00670 
00671   // Make the information visible, so that a user can
00672   // get to know what's going on during the gpg calls.
00673   kDebug( 5326 ) <<"gpg stderr:" << error;
00674 
00675   return childExitStatus;
00676 #else // HAVE_SYS_POLL_H
00677 #ifdef __GNUC__
00678 #warning WIN32 libkpgp: GnuPG support not ported to WIN32!
00679 #endif
00680   return 1;
00681 #endif
00682 }
00683 
00684 
00685 QByteArray
00686 Base::addUserId()
00687 {
00688   QByteArray cmd;
00689   QByteArray pgpUser = Module::getKpgp()->user();
00690 
00691   if(!pgpUser.isEmpty())
00692   {
00693     cmd += " -u 0x";
00694     cmd += pgpUser;
00695     return cmd;
00696   }
00697   return QByteArray();
00698 }
00699 
00700 
00701 } // namespace Kpgp

libkpgp

Skip menu "libkpgp"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal