2
Copyright (C) 2008- The University of Notre Dame
3
This software is distributed under the GNU General Public License.
4
See the file COPYING for details.
7
#include "chirp_group.h"
8
#include "chirp_types.h"
11
#include "stringtools.h"
20
extern const char *chirp_transient_path;
21
extern const char *chirp_group_base_url;
22
extern int chirp_group_cache_time;
25
Search for a given subject name in a group.
26
Return true if the member is found, false otherwise.
27
Works by downloading group files from a web server,
28
which are then cached for a configurable time, 15 minutes by default.
31
int chirp_group_lookup( const char *group, const char *subject )
33
char url[CHIRP_PATH_MAX];
34
char cachedir[CHIRP_PATH_MAX];
35
char cachepath[CHIRP_PATH_MAX];
36
char line[CHIRP_PATH_MAX];
39
if(!chirp_group_base_url) return 0;
43
sprintf(cachedir,"%s/.__groups",chirp_transient_path);
44
sprintf(cachepath,"%s/%s",cachedir,&group[6]);
46
if(stat(cachepath,&info)==0) {
47
int age = time(0) - info.st_mtime;
48
if(age<chirp_group_cache_time) {
54
sprintf(url,"%s%s",chirp_group_base_url,&group[6]);
55
debug(D_DEBUG,"fetching group %s from %s",group,url);
57
sprintf(line,"wget --no-check-certificate -q %s -O %s",url,cachepath);
59
debug(D_NOTICE,"failed to fetch group using: %s",line);
65
FILE *file = fopen(cachepath,"r");
68
while(fgets(line,sizeof(line),file)) {
71
// If it matches exactly, return.
72
if(!strcmp(line,subject)) {
77
// If the group entry does not have an auth method,
78
// and the subject is unix, look for equivalence after the colon.
80
if(!strchr(line,':') && !strncmp(subject,"unix:",5)) {
81
if(!strcmp(line,&subject[5])) {