File: helpfunc.c

package info (click to toggle)
pwdb 0.54preD-3
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 644 kB
  • ctags: 797
  • sloc: ansic: 8,459; makefile: 346; sh: 204
file content (146 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download | duplicates (2)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

/* Help functions for debugging, reporting, etc. */

#include "../_pwdb_internal.h"
#include "../_pwdb_macros.h"

/* 
 * radstr_ust = get a string of user_service_type
 */
const char * radstr_ust(u_int type) {
	switch (type) {
		case PW_LOGIN_USER:
			return "Login User";
		case PW_FRAMED_USER:
			return "Framed User";
		case PW_DIALBACK_LOGIN_USER:
			return "Dialback Login User";
		case PW_DIALBACK_FRAMED_USER:
			return "Dialback Framed User";
		default:
			return "Unknown type";
	}
	/* Not reached */
	return NULL;
}

/*
 * radstr_fp = get a string of framed_protocol
 */
const char * radstr_fp(u_int type) {
	switch(type) {
		case PW_PPP:
			return "PPP";
		case PW_SLIP:
			return "SLIP";
		default:
			return "Unknown";
	}
	/* Not reached */
	return NULL;
}

/*
 * radstr_fr = get a string of framed_routing
 */
const char * radstr_fr(u_int type) {
	switch(type) {
		case PW_NONE:
			return "None";
		case PW_BROADCAST:
			return "Broadcast";
		case PW_LISTEN:
			return "Listen";
		case PW_BROADCAST_LISTEN:
			return "Broadcast-Listen";
		default:
			return "Unknown";
	}
	/* Not reached */
	return NULL;
}

/*
 * radstr_ls = get a string of login_service
 */
const char * radstr_ls(u_int type) {
	switch(type) {
		case PW_TELNET:
			return "Telnet";
		case PW_RLOGIN:
			return "Rlogin";
		case PW_TCP_CLEAR:
			return "TCP Clear";
		case PW_PORTMASTER:
			return "PortMaster";
		default:
			return "Unknown";
	}
	/* Not reached */
	return NULL;
}

/*
 * radstr_ast = get a string of acct_status_type
 */
const char * radstr_ast(u_int type) {
	switch(type) {
		case PW_STATUS_START:
			return "Start";
		case PW_STATUS_STOP:
			return "Stop";
		default:
			return "Unknown";
	}
	/* Not reached */
	return NULL;
}

/*
 * radstr_aa = get a string of acct_authentic
 */
const char * radstr_aa(u_int type) {
	switch(type) {
		case PW_AUTH_NONE:
			return "None";
		case PW_AUTH_RADIUS:
			return "Radius";
		case PW_AUTH_LOCAL:
			return "Local";
		default:
			return "Unknown";
	}
	/* Not reached */
	return NULL;
}

int get_server_entries (char *hostname, char *secret) {
    char buffer[PATH_MAX];
    FILE *fserver;

    D(("called"));
    memset(buffer, 0, PATH_MAX);
    sprintf (buffer, "%s/%s", RADIUS_DIR, RADIUS_SRV);
    if ((fserver = fopen (buffer, "r")) == (FILE*)NULL) {
	D(("failed looking for %s",buffer));
	return PWDB_RADIUS_CONF_ERR;
    }

    while (fgets (buffer, sizeof(buffer), fserver) != (char*) NULL) {
	char *ptr;

	ptr = buffer;
	while (isspace(*ptr)) { 
	    ptr++;
	};
	if (*ptr == '#')
	    continue;
	/* Just look for one server now */
	if (sscanf (ptr, "%s%s", hostname, secret) != 2)
	    continue; /* invalid line */
	else
	    return PWDB_RADIUS_SUCCESS;
    }
    return PWDB_RADIUS_CONF_ERR;
}