-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaxcalluser.c
More file actions
77 lines (75 loc) · 1.46 KB
/
axcalluser.c
File metadata and controls
77 lines (75 loc) · 1.46 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
71
72
73
74
75
76
77
/* axcalluser.c - determine username corresponding to callsign */
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <errno.h>
#include "config.h"
#include "axcalluser.h"
int axcalluserid(char *call)
{
char callsign[10];
char username[80];
int id;
int userid = -1;
FILE *f = fopen(PROC_AX25_CALLS_FILE,"r");
if (f) { /* VE3TOK, 18Nov2014, return value usage */
if (fgets(username,79,f) == NULL) {
syslog(LOG_DEBUG, "Can't get username: %s", strerror(errno));
return 1;
}
while (fscanf(f," %d %9s",&id,callsign) != EOF) {
char *a,*b;
for (a=call,b=callsign;
*a && *b && toupper(*a)==toupper(*b) && *b!='-';
a++,b++) ;
if (!isalnum(*a) && !isalnum(*b)) {
userid = id;
}
}
}
fclose(f);
return userid;
}
char *getusername(int userid)
{
int colons;
int c,i;
char token[80];
static char name[80];
char *retval = NULL;
FILE *f;
f = fopen("/etc/passwd","r");
if (f) {
i = 0;
colons = 0;
while ((c = getc(f)) != EOF) {
switch (c) {
case ':':
token[i] = '\0';
colons++;
if (colons == 3) {
if (userid == atoi(token)) {
retval = name;
goto endloop;
}
} else if (colons == 1) {
strcpy(name,token);
}
i = 0;
break;
case '\n':
colons = 0;
i = 0;
break;
default:
token[i++] = c;
break;
}
}
endloop:
fclose(f);
}
return retval;
}