]> andersk Git - openssh.git/blobdiff - ssh-keysign.c
- (tim) [configure.ac] Bug #1149. Changes in QNX section only. Patch by
[openssh.git] / ssh-keysign.c
index e642948a0f78c4ebc0e784b725cfe17367402c32..dae3a2e8c91b811c267b61dfd1deaa8efe62618c 100644 (file)
@@ -22,7 +22,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "includes.h"
-RCSID("$OpenBSD: ssh-keysign.c,v 1.16 2004/04/18 23:10:26 djm Exp $");
+RCSID("$OpenBSD: ssh-keysign.c,v 1.19 2005/09/13 23:40:07 djm Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/rand.h>
@@ -41,15 +41,12 @@ RCSID("$OpenBSD: ssh-keysign.c,v 1.16 2004/04/18 23:10:26 djm Exp $");
 #include "canohost.h"
 #include "pathnames.h"
 #include "readconf.h"
+#include "uidswap.h"
 
 /* XXX readconf.c needs these */
 uid_t original_real_uid;
 
-#ifdef HAVE___PROGNAME
 extern char *__progname;
-#else
-char *__progname;
-#endif
 
 static int
 valid_request(struct passwd *pw, char *host, Key **ret, u_char *data,
@@ -151,11 +148,22 @@ main(int argc, char **argv)
        u_int slen, dlen;
        u_int32_t rnd[256];
 
+       /* Ensure that stdin and stdout are connected */
+       if ((fd = open(_PATH_DEVNULL, O_RDWR)) < 2)
+               exit(1);
+       /* Leave /dev/null fd iff it is attached to stderr */
+       if (fd > 2)
+               close(fd);
+
        key_fd[0] = open(_PATH_HOST_RSA_KEY_FILE, O_RDONLY);
        key_fd[1] = open(_PATH_HOST_DSA_KEY_FILE, O_RDONLY);
 
-       seteuid(getuid());
-       setuid(getuid());
+       original_real_uid = getuid();   /* XXX readconf.c needs this */
+       if ((pw = getpwuid(original_real_uid)) == NULL)
+               fatal("getpwuid failed");
+       pw = pwcopy(pw);
+
+       permanently_set_uid(pw);
 
        init_rng();
        seed_rng();
@@ -166,7 +174,6 @@ main(int argc, char **argv)
 #endif
 
        /* verify that ssh-keysign is enabled by the admin */
-       original_real_uid = getuid();   /* XXX readconf.c needs this */
        initialize_options(&options);
        (void)read_config_file(_PATH_HOST_CONFIG_FILE, "", &options, 0);
        fill_default_options(&options);
@@ -177,10 +184,6 @@ main(int argc, char **argv)
        if (key_fd[0] == -1 && key_fd[1] == -1)
                fatal("could not open any host key");
 
-       if ((pw = getpwuid(getuid())) == NULL)
-               fatal("getpwuid failed");
-       pw = pwcopy(pw);
-
        SSLeay_add_all_algorithms();
        for (i = 0; i < 256; i++)
                rnd[i] = arc4random();
This page took 0.033063 seconds and 4 git commands to generate.