~ubuntu-branches/ubuntu/trusty/rsync/trusty

« back to all changes in this revision

Viewing changes to chmod.c

  • Committer: Package Import Robot
  • Author(s): Paul Slootman
  • Date: 2013-10-27 12:01:10 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20131027120110-mpr03n5scqmf40mi
Tags: 3.1.0-2
fix build failure if zlib1g-dev package is not installed;
solved by building without the included zlib source and adding a
build-depends on zlib1g-dev >= 1:1.2.8
closes:32379

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Implement the core of the --chmod option.
3
3
 *
4
4
 * Copyright (C) 2002 Scott Howard
5
 
 * Copyright (C) 2005-2009 Wayne Davison
 
5
 * Copyright (C) 2005-2013 Wayne Davison
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
19
19
 */
20
20
 
21
21
#include "rsync.h"
 
22
#include "itypes.h"
22
23
 
23
24
extern mode_t orig_umask;
24
25
 
35
36
#define CHMOD_ADD 1
36
37
#define CHMOD_SUB 2
37
38
#define CHMOD_EQ  3
 
39
#define CHMOD_SET 4
38
40
 
39
41
#define STATE_ERROR 0
40
42
#define STATE_1ST_HALF 1
41
43
#define STATE_2ND_HALF 2
 
44
#define STATE_OCTAL_NUM 3
42
45
 
43
46
/* Parse a chmod-style argument, and break it down into one or more AND/OR
44
47
 * pairs in a linked list.  We return a pointer to new items on succcess
87
90
                                curr_mode->ModeAND = CHMOD_BITS - (where * 7) - (topoct ? topbits : 0);
88
91
                                curr_mode->ModeOR  = bits + topoct;
89
92
                                break;
 
93
                        case CHMOD_SET:
 
94
                                curr_mode->ModeAND = 0;
 
95
                                curr_mode->ModeOR  = bits;
 
96
                                break;
90
97
                        }
91
98
 
92
99
                        curr_mode->flags = flags;
99
106
                        where = what = op = topoct = topbits = flags = 0;
100
107
                }
101
108
 
102
 
                if (state != STATE_2ND_HALF) {
 
109
                switch (state) {
 
110
                case STATE_1ST_HALF:
103
111
                        switch (*modestr) {
104
112
                        case 'D':
105
113
                                if (flags & FLAG_FILES_ONLY)
138
146
                                state = STATE_2ND_HALF;
139
147
                                break;
140
148
                        default:
141
 
                                state = STATE_ERROR;
 
149
                                if (isDigit(modestr) && *modestr < '8' && !where) {
 
150
                                        op = CHMOD_SET;
 
151
                                        state =  STATE_OCTAL_NUM;
 
152
                                        where = 1;
 
153
                                        what = *modestr - '0';
 
154
                                } else
 
155
                                        state = STATE_ERROR;
142
156
                                break;
143
157
                        }
144
 
                } else {
 
158
                        break;
 
159
                case STATE_2ND_HALF:
145
160
                        switch (*modestr) {
146
161
                        case 'r':
147
162
                                what |= 4;
168
183
                                state = STATE_ERROR;
169
184
                                break;
170
185
                        }
 
186
                        break;
 
187
                case STATE_OCTAL_NUM:
 
188
                        if (isDigit(modestr) && *modestr < '8') {
 
189
                                what = what*8 + *modestr - '0';
 
190
                                if (what > CHMOD_BITS)
 
191
                                        state = STATE_ERROR;
 
192
                        } else
 
193
                                state = STATE_ERROR;
 
194
                        break;
171
195
                }
172
196
                modestr++;
173
197
        }