mkusers.c
上传用户:lukesailor
上传日期:2007-01-04
资源大小:27k
文件大小:1k
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <pwd.h>
- #include <grp.h>
- int main( int argc, char ** argv ) {
- int f;
- char dummy[17];
- f = open("/var/adm/ftp/users", O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (f>=0) {
- struct passwd * pw;
- while((pw = getpwent()) != NULL) {
- lseek(f, 9*pw->pw_uid, SEEK_SET);
- sprintf( dummy, "%s%s", pw->pw_name, " " );
- write(f, dummy, 8);
- }
- close(f);
- } else {
- exit( 1 );
- }
- f = open("/var/adm/ftp/groups", O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (f>=0) {
- struct group * gr;
- while((gr = getgrent()) != NULL) {
- lseek(f, 9*gr->gr_gid, SEEK_SET);
- sprintf( dummy, "%s%s", gr->gr_name, " " );
- write(f, dummy, 8);
- }
- close(f);
- } else {
- exit( 2 );
- }
- exit( 0 );
- }