/[LeafOK_CVS]/pvpgn-1.7.4/src/bnpass/bnpass.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/bnpass/bnpass.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
no message

1 sysadm 1.1 /*
2     * Copyright (C) 1999 Ross Combs (rocombs@cs.nmsu.edu)
3     *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License
6     * as published by the Free Software Foundation; either version 2
7     * of the License, or (at your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with this program; if not, write to the Free Software
16     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17     */
18     #include "common/setup_before.h"
19     #ifdef HAVE_STDDEF_H
20     # include <stddef.h>
21     #else
22     # ifndef NULL
23     # define NULL ((void *)0)
24     # endif
25     #endif
26     #ifdef STDC_HEADERS
27     # include <stdlib.h>
28     #endif
29     #include <stdio.h>
30     #include "compat/exitstatus.h"
31     #include <ctype.h>
32     #ifdef HAVE_STRING_H
33     # include <string.h>
34     #else
35     # ifdef HAVE_STRINGS_H
36     # include <strings.h>
37     # endif
38     #endif
39     #include "common/eventlog.h"
40     #include "common/bnethash.h"
41     #include "common/version.h"
42     #include "common/setup_after.h"
43    
44    
45     static void usage(char const * progname)
46     {
47     fprintf(stderr,
48     "usage: %s [<options>] [--] [<cleartextpassword>]\n"
49     " -h, --help, --usage show this information and exit\n"
50     " -v, --version print version number and exit\n",progname);
51    
52     exit(STATUS_FAILURE);
53     }
54    
55    
56     extern int main(int argc, char * argv[])
57     {
58    
59     char const * pass=NULL;
60     int a;
61     int forcepass=0;
62    
63     if (argc<1 || !argv || !argv[0])
64     {
65     fprintf(stderr,"bad arguments\n");
66     return STATUS_FAILURE;
67     }
68    
69     for (a=1; a<argc; a++)
70     if (forcepass && !pass)
71     pass = argv[a];
72     else if (strcmp(argv[a],"-")==0 && !pass)
73     pass = argv[a];
74     else if (argv[a][0]!='-' && !pass)
75     pass = argv[a];
76     else if (forcepass || argv[a][0]!='-' || strcmp(argv[a],"-")==0)
77     {
78     fprintf(stderr,"%s: extra password argument \"%s\"\n",argv[0],argv[a]);
79     usage(argv[0]);
80     }
81     else if (strcmp(argv[a],"--")==0)
82     forcepass = 1;
83     else if (strcmp(argv[a],"-v")==0 || strcmp(argv[a],"--version")==0)
84     {
85     printf("version "PVPGN_VERSION"\n");
86     return STATUS_SUCCESS;
87     }
88     else if (strcmp(argv[a],"-h")==0 || strcmp(argv[a],"--help")==0 || strcmp(argv[a],"--usage")
89     ==0)
90     usage(argv[0]);
91     else
92     {
93     fprintf(stderr,"%s: unknown option \"%s\"\n",argv[0],argv[a]);
94     usage(argv[0]);
95     }
96    
97     {
98     char buff[256];
99     t_hash hash;
100     unsigned int i;
101    
102     eventlog_set(stderr); /* bnet_hash() and friends use eventlog */
103    
104     if (!pass)
105     {
106     printf("Enter password to hash: ");
107     fflush(stdout);
108     fgets(buff,256,stdin);
109     if (buff[0]!='\0')
110     buff[strlen(buff)-1] = '\0';
111     }
112     else
113     {
114     strncpy(buff,pass,sizeof(buff));
115     buff[sizeof(buff)-1] = '\0';
116     }
117    
118     /* FIXME: what is the max password length? */
119     for (i=0; i<strlen(buff); i++)
120     if (isascii((int)buff[i]) && isupper((int)buff[i])) /* some tolower()'s are broken */
121     buff[i] = tolower((int)buff[i]);
122    
123     bnet_hash(&hash,strlen(buff),buff);
124     printf("\"BNET\\\\acct\\\\passhash1\"=\"%s\"\n",hash_get_str(hash));
125     }
126    
127     return STATUS_SUCCESS;
128     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1