Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
17
Добавлен:
01.05.2014
Размер:
734 б
Скачать
#include <iostream.h>

#include <stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <pwd.h>

int main (int argc, char* argv[])

{

if (argc < 3)

{

cerr << "Usage: " << argv[0] << " <usr_name> <file> ...\n";

return 1;

}

struct passwd * pwd = getpwnam(argv[1]); /* convert user name to UID */

uid_t UID = pwd->pw_uid;

struct stat statv;

if (UID == (uid_t)-1)

cerr<< "Invalid user name\n";

else for (int i=2; i < argc; i++) /* do for each file specified */

if (stat(argv[i],&statv)==0)

{

if (chown(argv[i], UID, statv.st_gid)) perror("chown");

} else perror("stat");

return 0;

}
Соседние файлы в папке ch7