~ubuntu-branches/ubuntu/lucid/rsync/lucid

« back to all changes in this revision

Viewing changes to util.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul Slootman
  • Date: 2009-06-17 13:43:12 UTC
  • mfrom: (1.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090617134312-aopuowraetuj41s8
Tags: 3.0.6-1
* new upstream release.
* Manpage now states that MD5 is used for protocol version 30 and higher.
  closes:#520330
* Updated to standards version 3.8.2. Added debian/README.source .
* Added lintian override for embedded-zlib, as this is a modified version
  optimized for the rsync protocol. I.e. the standard zlib version will not
  work as well.
* Added a 'status' option to the init.d script.
  closes:#492138
* Manpage now declares --delete-during to be the default in the summary.
  closes:#472767,#476368

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 1996-2000 Andrew Tridgell
5
5
 * Copyright (C) 1996 Paul Mackerras
6
6
 * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
7
 
 * Copyright (C) 2003-2008 Wayne Davison
 
7
 * Copyright (C) 2003-2009 Wayne Davison
8
8
 *
9
9
 * This program is free software; you can redistribute it and/or modify
10
10
 * it under the terms of the GNU General Public License as published by
1168
1168
        return 1;
1169
1169
}
1170
1170
 
1171
 
/**
1172
 
 * Determine if a symlink points outside the current directory tree.
 
1171
/* Determine if a symlink points outside the current directory tree.
1173
1172
 * This is considered "unsafe" because e.g. when mirroring somebody
1174
1173
 * else's machine it might allow them to establish a symlink to
1175
1174
 * /etc/passwd, and then read it through a web server.
1176
1175
 *
 
1176
 * Returns 1 if unsafe, 0 if safe.
 
1177
 *
1177
1178
 * Null symlinks and absolute symlinks are always unsafe.
1178
1179
 *
1179
1180
 * Basically here we are concerned with symlinks whose target contains
1181
1182
 * transferred directory.  We are not allowed to go back up and
1182
1183
 * reenter.
1183
1184
 *
1184
 
 * @param dest Target of the symlink in question.
1185
 
 *
1186
 
 * @param src Top source directory currently applicable.  Basically this
1187
 
 * is the first parameter to rsync in a simple invocation, but it's
1188
 
 * modified by flist.c in slightly complex ways.
1189
 
 *
1190
 
 * @retval True if unsafe
1191
 
 * @retval False is unsafe
1192
 
 *
1193
 
 * @sa t_unsafe.c
1194
 
 **/
 
1185
 * "dest" is the target of the symlink in question.
 
1186
 *
 
1187
 * "src" is the top source directory currently applicable at the level
 
1188
 * of the referenced symlink.  This is usually the symlink's full path
 
1189
 * (including its name), as referenced from the root of the transfer. */
1195
1190
int unsafe_symlink(const char *dest, const char *src)
1196
1191
{
1197
1192
        const char *name, *slash;
1203
1198
 
1204
1199
        /* find out what our safety margin is */
1205
1200
        for (name = src; (slash = strchr(name, '/')) != 0; name = slash+1) {
1206
 
                if (strncmp(name, "../", 3) == 0) {
1207
 
                        depth = 0;
1208
 
                } else if (strncmp(name, "./", 2) == 0) {
1209
 
                        /* nothing */
1210
 
                } else {
 
1201
                /* ".." segment starts the count over.  "." segment is ignored. */
 
1202
                if (*name == '.' && (name[1] == '/' || (name[1] == '.' && name[2] == '/'))) {
 
1203
                        if (name[1] == '.')
 
1204
                                depth = 0;
 
1205
                } else
1211
1206
                        depth++;
1212
 
                }
 
1207
                while (slash[1] == '/') slash++; /* just in case src isn't clean */
1213
1208
        }
1214
 
        if (strcmp(name, "..") == 0)
 
1209
        if (*name == '.' && name[1] == '.' && name[2] == '\0')
1215
1210
                depth = 0;
1216
1211
 
1217
1212
        for (name = dest; (slash = strchr(name, '/')) != 0; name = slash+1) {
1218
 
                if (strncmp(name, "../", 3) == 0) {
1219
 
                        /* if at any point we go outside the current directory
1220
 
                           then stop - it is unsafe */
1221
 
                        if (--depth < 0)
1222
 
                                return 1;
1223
 
                } else if (strncmp(name, "./", 2) == 0) {
1224
 
                        /* nothing */
1225
 
                } else {
 
1213
                if (*name == '.' && (name[1] == '/' || (name[1] == '.' && name[2] == '/'))) {
 
1214
                        if (name[1] == '.') {
 
1215
                                /* if at any point we go outside the current directory
 
1216
                                   then stop - it is unsafe */
 
1217
                                if (--depth < 0)
 
1218
                                        return 1;
 
1219
                        }
 
1220
                } else
1226
1221
                        depth++;
1227
 
                }
 
1222
                while (slash[1] == '/') slash++;
1228
1223
        }
1229
 
        if (strcmp(name, "..") == 0)
 
1224
        if (*name == '.' && name[1] == '.' && name[2] == '\0')
1230
1225
                depth--;
1231
1226
 
1232
 
        return (depth < 0);
 
1227
        return depth < 0;
1233
1228
}
1234
1229
 
1235
1230
#define HUMANIFY(mult) \