init commit
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
DIR *dir = opendir(argv[1]);
|
||||
unsigned long long sum = 0;
|
||||
struct dirent *de;
|
||||
while (de = readdir(dir)) {
|
||||
char *name = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(name, PATH_MAX, "%s/%s", argv[1], de->d_name);
|
||||
|
||||
struct stat st;
|
||||
if (lstat(name, &st) < 0) {
|
||||
continue;
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
sum += st.st_size;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
printf("%d\n", sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <linux/limits.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
DIR *dir = opendir(argv[1]);
|
||||
struct dirent *de;
|
||||
while (de = readdir(dir)) {
|
||||
char *name = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(name, PATH_MAX, "%s/%s", argv[1], de->d_name);
|
||||
|
||||
struct stat st;
|
||||
if (lstat(name, &st) < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!(S_ISREG(st.st_mode))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (access(name, 3)) {
|
||||
continue;
|
||||
}
|
||||
int len = strlen(name);
|
||||
|
||||
if (name[len - 1] == '~' || (len >= 4 && strcmp(name + strlen(name) - 4, ".bak") == 0)) {
|
||||
unlink(name);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
// подкаталог пустой
|
||||
// совпадают айдишники
|
||||
// есть права у остальных на запись
|
||||
// rmdir
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <linux/limits.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
DIR *dir = opendir(argv[1]);
|
||||
struct dirent *de;
|
||||
while (de = readdir(dir)) {
|
||||
if ((de->d_name[0] == '.' && strlen(de->d_name) == 1) ||
|
||||
(strlen(de->d_name) == 2) && !strcmp(de->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
char *name = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(name, PATH_MAX, "%s/%s", argv[1], de->d_name);
|
||||
|
||||
struct stat st;
|
||||
if (lstat(name, &st) < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!(S_ISDIR(st.st_mode))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (st.st_uid != getuid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(st.st_mode & 2)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int num_files = 0;
|
||||
DIR *dirt = opendir(name);
|
||||
while (readdir(dirt)) {
|
||||
num_files++;
|
||||
if (num_files > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_files > 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
closedir(dirt);
|
||||
rmdir(name);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user