+const char *
+get_password() { /* only run as root */
+ const char *rval;
+ struct passwd *pw;
+
+ if(geteuid() != 0) {
+ fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
+ exit(EXIT_FAILURE);
+ }
+ pw = getpwuid(getuid());
+ endpwent();
+ rval = pw->pw_passwd;
+
+#if HAVE_SHADOW_H
+ {
+ struct spwd *sp;
+ sp = getspnam(getenv("USER"));
+ endspent();
+ rval = sp->sp_pwdp;
+ }
+#endif
+ /* drop privileges */
+ if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
+ fputs("slock: cannot drop privileges\n",stdout);
+ exit(EXIT_FAILURE);
+ }
+ return rval;
+}
+