File: cvm-v1checkpassword.c

package info (click to toggle)
cvm 0.90-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 836 kB
  • ctags: 555
  • sloc: ansic: 3,848; sh: 1,131; makefile: 118; sql: 15
file content (70 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* cvm/cvm-v1checkpassword.c - Checkpassword emulator for CVM
 * Copyright (C)2006  Bruce Guenter <bruce@untroubled.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <misc/ucspi.h>
#include <msg/msg.h>
#include "v1client.h"

const char program[] = "cvm-v1checkpassword";
const int msg_show_pid = 0;

static char buffer[513];
static char* pass;

void get_data(void)
{
  unsigned buflen;
  unsigned rd;

  for (buflen = 0; buflen < sizeof buffer; buflen += rd) {
    do
      rd = read(3, buffer+buflen, sizeof buffer - buflen);
    while ((rd == (unsigned)-1) && (errno == EINTR));
    if (rd == (unsigned)-1) exit(111);	/* Read error */
    if (rd == 0) break;
  }
  close(3);
  if (buflen >= sizeof buffer) exit(2); /* Buffer too long */
  if ((pass = memchr(buffer, 0, buflen)) == 0) exit(2);	/* No password */
  ++pass;
  if (memchr(pass, 0, buflen-(pass-buffer)) == 0) exit(2); /* No terminator */
}

int main(int argc, char** argv)
{
  int i;
  const char* tokens[2];
  
  if (argc < 3)
    die3(111, "usage: ", program, " cvmodule program [args ...]");

  get_data();
  tokens[0] = pass;
  tokens[1] = 0;
  if ((i = cvm_client_authenticate(argv[1], buffer, ucspi_localhost(),
				   tokens, 1)) != 0) return i;

  if (!cvm_client_setugid()) return 111;
  if (!cvm_client_setenv()) return 111;

  execvp(argv[2], argv+2);
  return 111;
}