Changeset 215

Show
Ignore:
Timestamp:
04/06/05 09:45:26 (4 years ago)
Author:
athomas
Message:

op will now read all config files in /etc/op.d with a .conf extension. This
is a clean way of adding extra commands without having to manipulate op.conf.
op.conf does not have to be present at all.

Useful for dropping in op config with other packages or when adding config
to systems in bulk.

Also made error reporting a bit smarter when config files are missing or have
incorrect permissions.

This resolves #3.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • op/trunk/defs.h

    r213 r215  
    3232 
    3333int ReadFile(char *file); 
     34int ReadDir(char *dir); 
    3435int CountArgs(cmd_t *cmd); 
    3536int atov(char *str, int type); 
     
    3738#define MAXSTRLEN       2048 
    3839#define OP_ACCESS       "/etc/op.conf" 
    39 #define VERSION     "1.25" 
     40#define OP_ACCESS_DIR   "/etc/op.d" 
     41#define VERSION     "1.26" 
    4042 
    4143#define VAR_EXPAND_LEN  8192 
  • op/trunk/main.c

    r213 r215  
    2525#include <ctype.h> 
    2626#include <string.h> 
     27#include <dirent.h> 
    2728#include "defs.h" 
    2829#include "regexp.h" 
     
    8990} 
    9091 
     92int ReadDir( char *dir ) 
     93{ 
     94DIR *d; 
     95 
     96        if ((d = opendir(dir)) != NULL) 
     97        { 
     98        struct dirent *f; 
     99        int successes = 0; 
     100 
     101                while ((f = readdir(d))) 
     102                { 
     103                char full_path[PATH_MAX]; 
     104 
     105                        if (f->d_name[0] == '.' || (strlen(f->d_name) > 5 && strcmp(f->d_name + strlen(f->d_name) - 5, ".conf"))) 
     106                                continue; 
     107#ifdef HAVE_SNPRINTF 
     108                        snprintf(full_path, PATH_MAX, "%s/%s", OP_ACCESS_DIR, f->d_name); 
     109#else 
     110                        sprintf(full_path, "%s/%s", OP_ACCESS_DIR, f->d_name); 
     111#endif 
     112                        if (ReadFile(full_path)) 
     113                                ++successes; 
     114                } 
     115                closedir(d); 
     116                return successes; 
     117        } 
     118        return 0; 
     119} 
     120 
    91121int main(argc, argv) 
    92122int     argc; 
     
    97127        cmd_t           *cmd, *def, *new; 
    98128        struct passwd   *pw; 
    99         int             hflag = 0
     129        int             hflag = 0, read_conf = 0, read_conf_dir = 0
    100130        char            *uptr = NULL; 
    101131        char            cmd_s[MAXSTRLEN]; 
     
    161191                fatal(0, "openlog failed"); 
    162192#endif 
    163         ReadFile( OP_ACCESS ); 
     193        read_conf = ReadFile( OP_ACCESS ); 
     194        read_conf_dir = ReadDir( OP_ACCESS_DIR ); 
     195 
     196        if (!read_conf && !read_conf_dir) 
     197                fatal(1, "Could not open %s or any configuration files in %s", OP_ACCESS, OP_ACCESS_DIR); 
    164198 
    165199        if (hflag) { 
  • op/trunk/Makefile

    r210 r215  
    44CC=gcc 
    55INC= -I. -Wall 
    6 LIBS= -ll -L/lib -lpam -lcrypt 
     6LIBS= -ll -L/lib -lcrypt 
    77DESTDIR= 
    88PREFIX=/usr 
     9CONFDIR= $(DESTDIR)/etc/op.d 
    910BINDIR= $(DESTDIR)$(PREFIX)/bin 
    1011BINOWN= root 
     
    2021#GLOBALOPTS=-DDEBUG 
    2122# 
    22 # Linux 2.0.30 
     23# Linux with PAM 
    2324# 
    24 #OPTS= -DUSE_SHADOW -g 
    25 OPTS= -DXAUTH=\"/usr/X11R6/bin/xauth\" -DUSE_PAM -DHAVE_SNPRINTF -g 
    26 LDFLAGS = -g 
     25#OPTS= -DXAUTH=\"/usr/X11R6/bin/xauth\" -DUSE_PAM -DHAVE_SNPRINTF -g 
     26#LDFLAGS = -g -lpam 
     27
     28# Linux without PAM (eg. Slackware) 
     29
     30OPTS= -DXAUTH=\"/usr/X11R6/bin/xauth\" -DHAVE_SNPRINTF -DUSE_SHADOW -g 
    2731# 
    2832# 
     
    7882op.list: op.list.in 
    7983        sed -e "s/@VERSION@/`grep VERSION defs.h | cut -d\\\" -f2`/" < op.list.in > op.list 
    80 install: install-prog install-man 
    81 install-prog: 
     84install: op 
    8285        mkdir -p $(BINDIR) 
    8386        $(INSTALL) 
    84 install-man: 
    8587        mkdir -p $(MANDIR) 
    8688        $(INSTALL-MAN) 
     89        mkdir -p $(CONFDIR) 
    8790 
    8891pkg: op