-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdict.cpp
More file actions
70 lines (59 loc) · 1.54 KB
/
Copy pathdict.cpp
File metadata and controls
70 lines (59 loc) · 1.54 KB
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
#include "utiles.h"
#include <stdio.h>
#include <string.h>
FILE * open_dict( char * dict_file )
{
FILE * fp = NULL;
fp = fopen( dict_file, "r" );
if ( !fp )
{
_sshwp_debug( "Open password dictionary(%s) failed.\n", dict_file );
return NULL;
}
return fp;
}
// 返回读取一行字符的长度.
int read_user_info( FILE *fp, PUSR_INF pusr_inf, char * username )
{
char line[BUFFER_SIZE] = {0};
// 如果是服务器端关闭了链接,不需要读取字典,该密码组需要重新验证
if ( pusr_inf->rflag == REMOTE_OPENED )
{
if ( fgets( line, BUFFER_SIZE, fp ) == NULL )
{
_sshwp_debug( "Read password dictionary failed.\n" );
fclose( fp );
return -1;
}
}
else
{
pusr_inf->rflag = REMOTE_OPENED;
return pusr_inf->dict_line_len;
}
int r = strlen( line ) + 1;
pusr_inf->dict_line_len = r;
char *pcspace = NULL;
char *pline_feed = NULL;
pline_feed = strchr( line, '\r' );
if ( pline_feed )
*pline_feed = 0;
pline_feed = strchr( line, '\n' );
if ( pline_feed )
*pline_feed = 0;
pcspace = strchr( line, ' ' );
if ( pcspace == NULL && username == NULL )
return -1;
if ( pcspace == NULL && username != NULL )
{
strcpy( pusr_inf->username, username );
strcpy( pusr_inf->password, pcspace + 1);
}
else if ( pcspace )
{
*pcspace = 0;
strcpy( pusr_inf->username, line );
strcpy( pusr_inf->password, pcspace + 1);
}
return r;
}