2 * PuTTY miscellaneous Unix stuff
11 #include <sys/types.h>
16 long tickcount_offset
= 0;
18 unsigned long getticks(void)
21 gettimeofday(&tv
, NULL
);
23 * We want to use milliseconds rather than microseconds,
24 * because we need a decent number of them to fit into a 32-bit
25 * word so it can be used for keepalives.
27 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000 + tickcount_offset
;
30 Filename
filename_from_str(const char *str
)
33 strncpy(ret
.path
, str
, sizeof(ret
.path
));
34 ret
.path
[sizeof(ret
.path
)-1] = '\0';
38 const char *filename_to_str(const Filename
*fn
)
43 int filename_equal(Filename f1
, Filename f2
)
45 return !strcmp(f1
.path
, f2
.path
);
48 int filename_is_null(Filename fn
)
54 static FILE *debug_fp
= NULL
;
59 debug_fp
= fopen("debug.log", "w");
62 write(1, buf
, strlen(buf
));
69 char *get_username(void)
73 char *user
, *ret
= NULL
;
76 * First, find who we think we are using getlogin. If this
77 * agrees with our uid, we'll go along with it. This should
78 * allow sharing of uids between several login names whilst
79 * coping correctly with people who have su'ed.
87 if (p
&& p
->pw_uid
== uid
) {
89 * The result of getlogin() really does correspond to
95 * If that didn't work, for whatever reason, we'll do
96 * the simpler version: look up our uid in the password
97 * file and map it straight to a name.
110 * Display the fingerprints of the PGP Master Keys to the user.
111 * (This is here rather than in uxcons because it's appropriate even for
114 void pgp_fingerprints(void)
116 fputs("These are the fingerprints of the PuTTY PGP Master Keys. They can\n"
117 "be used to establish a trust path from this executable to another\n"
118 "one. See the manual for more information.\n"
119 "(Note: these fingerprints have nothing to do with SSH!)\n"
121 "PuTTY Master Key (RSA), 1024-bit:\n"
122 " " PGP_RSA_MASTER_KEY_FP
"\n"
123 "PuTTY Master Key (DSA), 1024-bit:\n"
124 " " PGP_DSA_MASTER_KEY_FP
"\n", stdout
);
128 * Set FD_CLOEXEC on a file descriptor
130 int cloexec(int fd
) {
133 fdflags
= fcntl(fd
, F_GETFD
);
134 if (fdflags
== -1) return -1;
135 return fcntl(fd
, F_SETFD
, fdflags
| FD_CLOEXEC
);
138 FILE *f_open(struct Filename filename
, char const *mode
, int is_private
)
141 return fopen(filename
.path
, mode
);
143 assert(mode
[0] == 'w'); /* is_private is meaningless for read */
144 int fd
= open(filename
.path
, O_WRONLY
| O_CREAT
| O_TRUNC
,
148 return fdopen(fd
, mode
);