From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: linux-kernel@vger.kernel.org
Subject: [Program for testing] cow behaviour for hard links
Date: Wed, 10 Mar 2004 20:35:40 +0100 [thread overview]
Message-ID: <20040310193540.GC4589@wohnheim.fh-wedel.de> (raw)
In-Reply-To: <20040310193429.GB4589@wohnheim.fh-wedel.de>
And here is the userspace program to fiddle with the cowlink flag.
Jörn
--
"Security vulnerabilities are here to stay."
-- Scott Culp, Manager of the Microsoft Security Response Center, 2001
/**
* cowlink - set, unset and query the cowlink flag to files
*
* Copyright (C) 2004 Jörn Engel <joern@wh.fh-wedel.de>
*
* This is *not* open source. The rights granted to anyone by the
* author are the rights to
* - look at the code,
* - make verbatim copies and distribute them,
* - compile it,
* - send patches to the author.
*
* Nothing else. If you don't like the license, feel free to discuss it
* over a beer. You can send me beer and discuss via email, if you like. ;)
*
* Seriously, this program shouldn't exist at all. It would make more sense
* to merge it into chmod, at least in the authors opinion. We'll see...
*
* Oh yeah, the compiled binary is free, there are no strings attached to
* it whatsoever.
*/
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#define F_LINUX_SPECIFIC_BASE 1024
#define F_SETCOW (F_LINUX_SPECIFIC_BASE+3)
#define F_GETCOW (F_LINUX_SPECIFIC_BASE+4)
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
static long mode = -1;
static long get = 0;
static int recursive = 0;
static void do_file(const char *name)
{
int fd, ret;
fd = open(name, O_RDONLY);
if (fd < 0)
return perror(name);
switch (mode) {
default:
break;
case 0: /* fall through */
case 1:
ret = fcntl(fd, F_SETCOW, mode);
if (ret)
return perror(name);
}
if (get) {
ret = fcntl(fd, F_GETCOW);
if (ret < 0)
return perror(name);
printf("%d %s\n", ret, name);
}
close(fd);
}
static void do_dir(const char *name)
{
do_file(name);
DIR *dir = opendir(name);
if (!dir) {
switch (errno) {
case ENOTDIR:
return;
default:
return perror(name);
}
}
if (!recursive)
return;
char *newname, *end;
{
size_t len = strlen(name);
newname = malloc(len + 4096);
strcpy(newname, name);
newname[len] = '/';
end = newname + len + 1;
}
for (struct dirent *de = readdir(dir); de; de = readdir(dir)) {
strcpy(end, de->d_name);
struct stat status;
lstat(newname, &status);
if (S_ISDIR(status.st_mode)) {
if (!strcmp(de->d_name, "."))
continue;
if (!strcmp(de->d_name, ".."))
continue;
do_dir(newname);
}
if (S_ISREG(status.st_mode))
do_file(newname);
}
free(newname);
closedir(dir);
}
int main(int argc, char **argv)
{
for (;;) {
int oi = 1;
char short_opts[] = "cgRrs";
static const struct option long_opts[] = {
{"clear", 0, 0, 'c'},
{"get", 0, 0, 'g'},
{"recursive", 0, 0, 'r'},
{"set", 0, 0, 's'},
{0, 0, 0, 0}
};
int c = getopt_long(argc, argv, short_opts, long_opts, &oi);
if (c == -1)
break;
switch (c) {
case 'c':
mode = 0;
break;
case 'g':
get = 1;
break;
case 'R': /* fall through */
case 'r':
recursive = 1;
break;
case 's':
mode = 1;
break;
default:
fprintf(stderr, "BUG\n");
exit(EXIT_FAILURE);
}
}
while (optind < argc)
do_dir(argv[optind++]);
return 0;
}
next prev parent reply other threads:[~2004-03-10 19:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-10 19:34 [PATCH " Jörn Engel
2004-03-10 19:35 ` Jörn Engel [this message]
2004-03-10 21:34 ` Jamie Lokier
2004-03-10 22:17 ` Jörn Engel
2004-03-10 23:07 ` Sytse Wielinga
2004-03-10 23:46 ` Sytse Wielinga
2004-03-12 17:48 ` Sytse Wielinga
2004-03-12 18:18 ` Jörn Engel
2004-03-12 18:29 ` Jörn Engel
2004-03-13 13:43 ` Pavel Machek
2004-03-13 19:48 ` Jörn Engel
2004-03-13 21:03 ` Pavel Machek
2004-03-15 7:45 ` Jamie Lokier
2004-03-15 10:27 ` Jörn Engel
2004-03-13 22:14 ` Jörn Engel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040310193540.GC4589@wohnheim.fh-wedel.de \
--to=joern@wohnheim.fh-wedel.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®