From 4013fe89dba7bcbd25ffded96d12bba6c9c78476 Mon Sep 17 00:00:00 2001 From: Dave Hibberd Date: Thu, 3 Sep 2015 20:01:45 +0100 Subject: Imported Upstream version 2.3.1 --- axcalluser.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 axcalluser.c (limited to 'axcalluser.c') diff --git a/axcalluser.c b/axcalluser.c new file mode 100644 index 0000000..107a285 --- /dev/null +++ b/axcalluser.c @@ -0,0 +1,77 @@ +/* axcalluser.c - determine username corresponding to callsign */ +#include +#include +#include +#include +#include +#include +#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; +} -- cgit v1.2.3