1 /*
2  * sf-get3.cc: Part of GNU CSSC.
3  *
4  *
5  *  Copyright (C) 1997, 1999, 2002, 2007, 2008, 2009, 2010, 2011, 2014,
6  *  2019 Free Software Foundation, Inc.
7  *
8  *  This program is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * CSSC was originally Based on MySC, by Ross Ridge, which was
22  * placed in the Public Domain.
23  *
24  *
25  * Members of the class sccs_file used by get and delta.
26  *
27  */
28 
29 #include <config.h>
30 
31 #include "cssc.h"
32 #include "sccsfile.h"
33 #include "seqstate.h"
34 #include "delta-iterator.h"
35 #include "file.h"
36 
37 /* Prepare a seqstate for use by marking which sequence numbers are to
38  * be included and which are to be excluded.
39  */
40 
41 bool
prepare_seqstate_2(seq_state & state,sid_list include,sid_list exclude,sccs_date cutoff_date)42 sccs_file::prepare_seqstate_2(seq_state &state, sid_list include,
43                             sid_list exclude, sccs_date cutoff_date)
44 {
45 
46   ASSERT(0 != delta_table);
47   const_delta_iterator iter(delta_table);
48 
49   while (iter.next())
50     {
51       sid const &id = iter->id();
52 
53       if (include.member(id))   // explicitly included on command line
54         {
55           state.set_explicitly_included(iter->seq(),
56 					(seq_no) seq_state::BY_COMMAND_LINE );
57         }
58       else if (exclude.member(id)) // explicitly included on command line
59         {
60           state.set_explicitly_excluded(iter->seq(),
61 					(seq_no) seq_state::BY_COMMAND_LINE );
62         }
63       else if (cutoff_date.valid() && iter->date() > cutoff_date)
64         {
65           // Delta not explicitly included/excluded by the user, but
66           // if it is newer than the cutoff date, we don't want it.
67           // This is the feature that allows us to retrieve a delta
68           // that was current at some time in the past.
69           state.set_excluded(iter->seq(), (seq_no) seq_state::BY_COMMAND_LINE);
70         }
71 
72       ASSERT(0 != delta_table);
73     }
74   ASSERT(0 != delta_table);
75 
76   return true;
77 }
78 
79 
prepare_seqstate(seq_state & state,seq_no seq,sid_list include,sid_list exclude,sccs_date cutoff_date)80 bool sccs_file::prepare_seqstate(seq_state &state, seq_no seq,
81                                  sid_list include,
82                                  sid_list exclude, sccs_date cutoff_date)
83 {
84     if (!prepare_seqstate_1(state, seq))
85         return false;
86 
87     if (!prepare_seqstate_2(state, include, exclude, cutoff_date))
88         return false;
89 
90     return true;
91 }
92 
93 
94 
95 
96 bool
authorised() const97 sccs_file::authorised() const
98 {
99   if (users.empty())
100     {
101       // If there is no list of authorized users, all users are authorised.
102       return true;
103     }
104 
105   const char *myself = get_user_name();
106   for (const auto& authorized_user : users)
107     {
108       if (isdigit(authorized_user[0]))
109 	{
110 	  // FIXME: don't use atoi, it doesn't do error detection well.
111 	  if (user_is_group_member(atoi(authorized_user.c_str())))
112 	    {
113 	      return true;
114 	    }
115 	}
116       else if (myself == authorized_user)
117 	{
118 	  return true;
119 	}
120     }
121   errormsg("%s: You are not authorized to make deltas.", name.c_str());
122   return false;
123 }
124 
125 
126 /* Local variables: */
127 /* mode: c++ */
128 /* End: */
129