12 //typedef ssize_t (*_read_f_t_)(int fd, void *buf, size_t count);
13 //static _read_f_t_ _read_f_ = NULL;
15 ssize_t
read(int fd
, void *buf
, size_t count
)
17 int (*real_read
)(int fd
, void *buf
, size_t count
) = NULL
;
22 warnx("intercepted fd=%d", fd
);
25 _read_f_ = (_read_f_t_)dlsym(RTLD_NEXT, "read");
26 warnx("-> %p", _read_f_);
28 errx(1, "dlsym: %s", dlerror());
32 void *handle
= dlopen("/lib/i386-linux-gnu/libc.so.6", RTLD_LAZY
);
34 errx(1, "dlopen: %s", dlerror());
35 real_read
= dlsym(handle
, "read");
36 if (real_read
== NULL
)
37 errx(1, "dlopen: %s", dlerror());
40 snprintf(fdpath
, 21, "/proc/self/fd/%d", fd
);
41 if(lstat(fdpath
, &st
) == 0)
43 if(major(st
.st_rdev
) == 5 && minor(st
.st_rdev
) == 0)
45 pwd
= getenv("CUPS_PASSWORD");
48 if(count
>= strlen(pwd
))
50 sprintf(buf
, "%s\n", pwd
);
55 warnx("Buffer is too small, %d, %d.", count
, stren(pwd
));
60 warnx("CUPS_PASSWORD is not set.");
66 warn("lstat: %s", fdpath
);
68 return real_read(fd
, buf
, count
);
69 // return _read_f_(fd, buf, count);
72 // Fordítás: gcc -s -x c cupspwd.c -fPIC -shared -o cupspwd.so
73 // Futtatás: CUPS_PASSWORD=xxx LD_PRELOAD=./cupspwd.so lpstat -l -t