File: module.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (66 lines) | stat: -rw-r--r-- 1,763 bytes parent folder | download | duplicates (7)
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
/* pwcmp/module.c - Password comparison module base code
 * Copyright (C) 2001  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 <string.h>
#include <unistd.h>
#include "module.h"

static char buf[4096];
static unsigned buflen;
static unsigned bufpos;
static const char* plain;
static const char* encod;

static int do_read(void)
{
  if (bufpos) {
    memmove(buf, buf+bufpos, buflen-bufpos);
    buflen -= bufpos;
  }
  while (buflen < sizeof buf) {
    const char* tmp;
    unsigned long rd;
    if (buflen) {
      if ((tmp = memchr(buf, 0, buflen)) != 0) {
	unsigned len;
	plain = buf;
	encod = tmp + 1;
	len = encod - buf;
	if ((tmp = memchr(encod, 0, buflen - len)) != 0) {
	  ++tmp;
	  bufpos = tmp - buf;
	  return 1;
	}
      }
    }
    if ((rd = read(0, buf + buflen, sizeof buf - buflen)) == 0 ||
	rd == (unsigned long)-1)
      break;
    buflen += rd;
  }
  return 0;
}

int main(void) 
{
  while (do_read()) {
    char tmp[1];
    tmp[0] = pwcmp_check(plain, encod) ? 1 : 0;
    if (write(1, tmp, 1) != 1) break;
  }
  return 1;
}