~ubuntu-branches/ubuntu/trusty/rpm/trusty

« back to all changes in this revision

Viewing changes to rpmsign.c

  • Committer: Package Import Robot
  • Author(s): Michal Čihař
  • Date: 2013-07-08 10:33:12 UTC
  • mfrom: (17.2.27 sid)
  • Revision ID: package-import@ubuntu.com-20130708103312-ig6gs0rgg4k851ym
Tags: 4.11.1-1
* New upstream release.
* Do not try to convert ancient rpmrc config file (Closes: #712448).
* Make rpm2cpio Multi-Arch: foreign (Closes: #713970).
* Use canonical VCS urls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
{
46
46
    int passPhrasePipe[2];
47
47
    int pid, status;
48
 
    int rc;
 
48
    int rc = -1;
49
49
    int xx;
50
50
 
51
51
    if (passPhrase == NULL)
52
52
        return -1;
53
53
 
54
54
    passPhrasePipe[0] = passPhrasePipe[1] = 0;
55
 
    xx = pipe(passPhrasePipe);
56
 
    if (!(pid = fork())) {
 
55
    if (pipe(passPhrasePipe))
 
56
        return -1;
 
57
 
 
58
    pid = fork();
 
59
    if (pid < 0) {
 
60
        close(passPhrasePipe[0]);
 
61
        close(passPhrasePipe[1]);
 
62
        return -1;
 
63
    }
 
64
 
 
65
    if (pid == 0) {
57
66
        char * cmd, * gpg_path;
58
67
        char *const *av;
59
68
        int fdno;
60
69
 
61
 
        xx = close(STDIN_FILENO);
62
 
        xx = close(STDOUT_FILENO);
63
 
        xx = close(passPhrasePipe[1]);
 
70
        close(STDIN_FILENO);
 
71
        close(STDOUT_FILENO);
 
72
        close(passPhrasePipe[1]);
64
73
        if ((fdno = open("/dev/null", O_RDONLY)) != STDIN_FILENO) {
65
74
            xx = dup2(fdno, STDIN_FILENO);
66
 
            xx = close(fdno);
 
75
            close(fdno);
67
76
        }
68
77
        if ((fdno = open("/dev/null", O_WRONLY)) != STDOUT_FILENO) {
69
78
            xx = dup2(fdno, STDOUT_FILENO);
70
 
            xx = close(fdno);
 
79
            close(fdno);
71
80
        }
72
81
        xx = dup2(passPhrasePipe[0], 3);
73
82
 
79
88
        
80
89
        cmd = rpmExpand("%{?__gpg_check_password_cmd}", NULL);
81
90
        rc = poptParseArgvString(cmd, NULL, (const char ***)&av);
82
 
        if (!rc)
 
91
        if (xx >= 0 && rc == 0) {
83
92
            rc = execve(av[0], av+1, environ);
84
 
 
85
 
        fprintf(stderr, _("Could not exec %s: %s\n"), "gpg",
86
 
                    strerror(errno));
 
93
            fprintf(stderr, _("Could not exec %s: %s\n"), "gpg",
 
94
                        strerror(errno));
 
95
        }
87
96
        _exit(EXIT_FAILURE);
88
97
    }
89
98
 
90
 
    xx = close(passPhrasePipe[0]);
 
99
    close(passPhrasePipe[0]);
91
100
    xx = write(passPhrasePipe[1], passPhrase, strlen(passPhrase));
92
101
    xx = write(passPhrasePipe[1], "\n", 1);
93
 
    xx = close(passPhrasePipe[1]);
94
 
 
95
 
    (void) waitpid(pid, &status, 0);
96
 
 
97
 
    return ((WIFEXITED(status) && WEXITSTATUS(status) == 0)) ? 0 : 1;
 
102
    close(passPhrasePipe[1]);
 
103
 
 
104
    if (xx >= 0 && waitpid(pid, &status, 0) >= 0)
 
105
        rc = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : 1;
 
106
 
 
107
    return rc;
98
108
}
99
109
 
100
110
/* TODO: permit overriding macro setup on the command line */