Deleted Added
full compact
sel_subs.c (90110) sel_subs.c (90113)
1/*-
2 * Copyright (c) 1992 Keith Muller.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 26 unchanged lines hidden (view full) ---

35 * SUCH DAMAGE.
36 */
37
38#ifndef lint
39#if 0
40static char sccsid[] = "@(#)sel_subs.c 8.1 (Berkeley) 5/31/93";
41#endif
42static const char rcsid[] =
1/*-
2 * Copyright (c) 1992 Keith Muller.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 26 unchanged lines hidden (view full) ---

35 * SUCH DAMAGE.
36 */
37
38#ifndef lint
39#if 0
40static char sccsid[] = "@(#)sel_subs.c 8.1 (Berkeley) 5/31/93";
41#endif
42static const char rcsid[] =
43 "$FreeBSD: head/bin/pax/sel_subs.c 90110 2002-02-02 06:48:10Z imp $";
43 "$FreeBSD: head/bin/pax/sel_subs.c 90113 2002-02-02 07:07:59Z imp $";
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <pwd.h>
50#include <grp.h>
51#include <stdio.h>
52#include <string.h>
53#include <strings.h>
54#include <unistd.h>
55#include <stdlib.h>
56#include "pax.h"
57#include "sel_subs.h"
58#include "extern.h"
59
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <pwd.h>
50#include <grp.h>
51#include <stdio.h>
52#include <string.h>
53#include <strings.h>
54#include <unistd.h>
55#include <stdlib.h>
56#include "pax.h"
57#include "sel_subs.h"
58#include "extern.h"
59
60static int str_sec(register char *, time_t *);
61static int usr_match(register ARCHD *);
62static int grp_match(register ARCHD *);
63static int trng_match(register ARCHD *);
60static int str_sec(char *, time_t *);
61static int usr_match(ARCHD *);
62static int grp_match(ARCHD *);
63static int trng_match(ARCHD *);
64
65static TIME_RNG *trhead = NULL; /* time range list head */
66static TIME_RNG *trtail = NULL; /* time range list tail */
67static USRT **usrtb = NULL; /* user selection table */
68static GRPT **grptb = NULL; /* group selection table */
69
70/*
71 * Routines for selection of archive members
72 */
73
74/*
75 * sel_chk()
76 * check if this file matches a specified uid, gid or time range
77 * Return:
78 * 0 if this archive member should be processed, 1 if it should be skipped
79 */
80
81int
64
65static TIME_RNG *trhead = NULL; /* time range list head */
66static TIME_RNG *trtail = NULL; /* time range list tail */
67static USRT **usrtb = NULL; /* user selection table */
68static GRPT **grptb = NULL; /* group selection table */
69
70/*
71 * Routines for selection of archive members
72 */
73
74/*
75 * sel_chk()
76 * check if this file matches a specified uid, gid or time range
77 * Return:
78 * 0 if this archive member should be processed, 1 if it should be skipped
79 */
80
81int
82sel_chk(register ARCHD *arcn)
82sel_chk(ARCHD *arcn)
83{
84 if (((usrtb != NULL) && usr_match(arcn)) ||
85 ((grptb != NULL) && grp_match(arcn)) ||
86 ((trhead != NULL) && trng_match(arcn)))
87 return(1);
88 return(0);
89}
90

--- 8 unchanged lines hidden (view full) ---

99/*
100 * usr_add()
101 * add a user match to the user match hash table
102 * Return:
103 * 0 if added ok, -1 otherwise;
104 */
105
106int
83{
84 if (((usrtb != NULL) && usr_match(arcn)) ||
85 ((grptb != NULL) && grp_match(arcn)) ||
86 ((trhead != NULL) && trng_match(arcn)))
87 return(1);
88 return(0);
89}
90

--- 8 unchanged lines hidden (view full) ---

99/*
100 * usr_add()
101 * add a user match to the user match hash table
102 * Return:
103 * 0 if added ok, -1 otherwise;
104 */
105
106int
107usr_add(register char *str)
107usr_add(char *str)
108{
108{
109 register u_int indx;
110 register USRT *pt;
111 register struct passwd *pw;
112 register uid_t uid;
109 u_int indx;
110 USRT *pt;
111 struct passwd *pw;
112 uid_t uid;
113
114 /*
115 * create the table if it doesn't exist
116 */
117 if ((str == NULL) || (*str == '\0'))
118 return(-1);
119 if ((usrtb == NULL) &&
120 ((usrtb = (USRT **)calloc(USR_TB_SZ, sizeof(USRT *))) == NULL)) {

--- 51 unchanged lines hidden (view full) ---

172/*
173 * usr_match()
174 * check if this files uid matches a selected uid.
175 * Return:
176 * 0 if this archive member should be processed, 1 if it should be skipped
177 */
178
179static int
113
114 /*
115 * create the table if it doesn't exist
116 */
117 if ((str == NULL) || (*str == '\0'))
118 return(-1);
119 if ((usrtb == NULL) &&
120 ((usrtb = (USRT **)calloc(USR_TB_SZ, sizeof(USRT *))) == NULL)) {

--- 51 unchanged lines hidden (view full) ---

172/*
173 * usr_match()
174 * check if this files uid matches a selected uid.
175 * Return:
176 * 0 if this archive member should be processed, 1 if it should be skipped
177 */
178
179static int
180usr_match(register ARCHD *arcn)
180usr_match(ARCHD *arcn)
181{
181{
182 register USRT *pt;
182 USRT *pt;
183
184 /*
185 * hash and look for it in the table
186 */
187 pt = usrtb[((unsigned)arcn->sb.st_uid) % USR_TB_SZ];
188 while (pt != NULL) {
189 if (pt->uid == arcn->sb.st_uid)
190 return(0);

--- 9 unchanged lines hidden (view full) ---

200/*
201 * grp_add()
202 * add a group match to the group match hash table
203 * Return:
204 * 0 if added ok, -1 otherwise;
205 */
206
207int
183
184 /*
185 * hash and look for it in the table
186 */
187 pt = usrtb[((unsigned)arcn->sb.st_uid) % USR_TB_SZ];
188 while (pt != NULL) {
189 if (pt->uid == arcn->sb.st_uid)
190 return(0);

--- 9 unchanged lines hidden (view full) ---

200/*
201 * grp_add()
202 * add a group match to the group match hash table
203 * Return:
204 * 0 if added ok, -1 otherwise;
205 */
206
207int
208grp_add(register char *str)
208grp_add(char *str)
209{
209{
210 register u_int indx;
211 register GRPT *pt;
212 register struct group *gr;
213 register gid_t gid;
210 u_int indx;
211 GRPT *pt;
212 struct group *gr;
213 gid_t gid;
214
215 /*
216 * create the table if it doesn't exist
217 */
218 if ((str == NULL) || (*str == '\0'))
219 return(-1);
220 if ((grptb == NULL) &&
221 ((grptb = (GRPT **)calloc(GRP_TB_SZ, sizeof(GRPT *))) == NULL)) {

--- 51 unchanged lines hidden (view full) ---

273/*
274 * grp_match()
275 * check if this files gid matches a selected gid.
276 * Return:
277 * 0 if this archive member should be processed, 1 if it should be skipped
278 */
279
280static int
214
215 /*
216 * create the table if it doesn't exist
217 */
218 if ((str == NULL) || (*str == '\0'))
219 return(-1);
220 if ((grptb == NULL) &&
221 ((grptb = (GRPT **)calloc(GRP_TB_SZ, sizeof(GRPT *))) == NULL)) {

--- 51 unchanged lines hidden (view full) ---

273/*
274 * grp_match()
275 * check if this files gid matches a selected gid.
276 * Return:
277 * 0 if this archive member should be processed, 1 if it should be skipped
278 */
279
280static int
281grp_match(register ARCHD *arcn)
281grp_match(ARCHD *arcn)
282{
282{
283 register GRPT *pt;
283 GRPT *pt;
284
285 /*
286 * hash and look for it in the table
287 */
288 pt = grptb[((unsigned)arcn->sb.st_gid) % GRP_TB_SZ];
289 while (pt != NULL) {
290 if (pt->gid == arcn->sb.st_gid)
291 return(0);

--- 31 unchanged lines hidden (view full) ---

323 * format: [yy[mm[dd[hh]]]]mm[.ss] and are comma separated.
324 * Time ranges are based on current time, so 1234 would specify a time of
325 * 12:34 today.
326 * Return:
327 * 0 if the time range was added to the list, -1 otherwise
328 */
329
330int
284
285 /*
286 * hash and look for it in the table
287 */
288 pt = grptb[((unsigned)arcn->sb.st_gid) % GRP_TB_SZ];
289 while (pt != NULL) {
290 if (pt->gid == arcn->sb.st_gid)
291 return(0);

--- 31 unchanged lines hidden (view full) ---

323 * format: [yy[mm[dd[hh]]]]mm[.ss] and are comma separated.
324 * Time ranges are based on current time, so 1234 would specify a time of
325 * 12:34 today.
326 * Return:
327 * 0 if the time range was added to the list, -1 otherwise
328 */
329
330int
331trng_add(register char *str)
331trng_add(char *str)
332{
332{
333 register TIME_RNG *pt;
334 register char *up_pt = NULL;
335 register char *stpt;
336 register char *flgpt;
337 register int dot = 0;
333 TIME_RNG *pt;
334 char *up_pt = NULL;
335 char *stpt;
336 char *flgpt;
337 int dot = 0;
338
339 /*
340 * throw out the badly formed time ranges
341 */
342 if ((str == NULL) || (*str == '\0')) {
343 paxwarn(1, "Empty time range string");
344 return(-1);
345 }

--- 117 unchanged lines hidden (view full) ---

463/*
464 * trng_match()
465 * check if this files mtime/ctime falls within any supplied time range.
466 * Return:
467 * 0 if this archive member should be processed, 1 if it should be skipped
468 */
469
470static int
338
339 /*
340 * throw out the badly formed time ranges
341 */
342 if ((str == NULL) || (*str == '\0')) {
343 paxwarn(1, "Empty time range string");
344 return(-1);
345 }

--- 117 unchanged lines hidden (view full) ---

463/*
464 * trng_match()
465 * check if this files mtime/ctime falls within any supplied time range.
466 * Return:
467 * 0 if this archive member should be processed, 1 if it should be skipped
468 */
469
470static int
471trng_match(register ARCHD *arcn)
471trng_match(ARCHD *arcn)
472{
472{
473 register TIME_RNG *pt;
473 TIME_RNG *pt;
474
475 /*
476 * have to search down the list one at a time looking for a match.
477 * remember time range limits are inclusive.
478 */
479 pt = trhead;
480 while (pt != NULL) {
481 switch(pt->flgs & CMPBOTH) {

--- 50 unchanged lines hidden (view full) ---

532 * str_sec()
533 * Convert a time string in the format of [yy[mm[dd[hh]]]]mm[.ss] to gmt
534 * seconds. Tval already has current time loaded into it at entry.
535 * Return:
536 * 0 if converted ok, -1 otherwise
537 */
538
539static int
474
475 /*
476 * have to search down the list one at a time looking for a match.
477 * remember time range limits are inclusive.
478 */
479 pt = trhead;
480 while (pt != NULL) {
481 switch(pt->flgs & CMPBOTH) {

--- 50 unchanged lines hidden (view full) ---

532 * str_sec()
533 * Convert a time string in the format of [yy[mm[dd[hh]]]]mm[.ss] to gmt
534 * seconds. Tval already has current time loaded into it at entry.
535 * Return:
536 * 0 if converted ok, -1 otherwise
537 */
538
539static int
540str_sec(register char *str, time_t *tval)
540str_sec(char *str, time_t *tval)
541{
541{
542 register struct tm *lt;
543 register char *dot = NULL;
542 struct tm *lt;
543 char *dot = NULL;
544
545 lt = localtime(tval);
546 if ((dot = strchr(str, '.')) != NULL) {
547 /*
548 * seconds (.ss)
549 */
550 *dot++ = '\0';
551 if (strlen(dot) != 2)

--- 59 unchanged lines hidden ---
544
545 lt = localtime(tval);
546 if ((dot = strchr(str, '.')) != NULL) {
547 /*
548 * seconds (.ss)
549 */
550 *dot++ = '\0';
551 if (strlen(dot) != 2)

--- 59 unchanged lines hidden ---