|
Lines 170-175
static char *auth_info_file = NULL;
Link Here
|
| 170 |
/* Name and directory of socket for authentication agent forwarding. */ |
170 |
/* Name and directory of socket for authentication agent forwarding. */ |
| 171 |
static char *auth_sock_name = NULL; |
171 |
static char *auth_sock_name = NULL; |
| 172 |
static char *auth_sock_dir = NULL; |
172 |
static char *auth_sock_dir = NULL; |
|
|
173 |
int remove_auth_sock_dir = 1; |
| 173 |
|
174 |
|
| 174 |
/* removes the agent forwarding socket */ |
175 |
/* removes the agent forwarding socket */ |
| 175 |
|
176 |
|
|
Lines 179-186
auth_sock_cleanup_proc(struct passwd *pw)
Link Here
|
| 179 |
if (auth_sock_name != NULL) { |
180 |
if (auth_sock_name != NULL) { |
| 180 |
temporarily_use_uid(pw); |
181 |
temporarily_use_uid(pw); |
| 181 |
unlink(auth_sock_name); |
182 |
unlink(auth_sock_name); |
| 182 |
rmdir(auth_sock_dir); |
183 |
free(auth_sock_name); |
| 183 |
auth_sock_name = NULL; |
184 |
auth_sock_name = NULL; |
|
|
185 |
|
| 186 |
if (remove_auth_sock_dir) |
| 187 |
rmdir(auth_sock_dir); |
| 188 |
free(auth_sock_dir); |
| 189 |
auth_sock_dir = NULL; |
| 184 |
restore_uid(); |
190 |
restore_uid(); |
| 185 |
} |
191 |
} |
| 186 |
} |
192 |
} |
|
Lines 189-194
static int
Link Here
|
| 189 |
auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw) |
195 |
auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw) |
| 190 |
{ |
196 |
{ |
| 191 |
Channel *nc; |
197 |
Channel *nc; |
|
|
198 |
char *path; |
| 192 |
int sock = -1; |
199 |
int sock = -1; |
| 193 |
|
200 |
|
| 194 |
if (auth_sock_name != NULL) { |
201 |
if (auth_sock_name != NULL) { |
|
Lines 199-215
auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw)
Link Here
|
| 199 |
/* Temporarily drop privileged uid for mkdir/bind. */ |
206 |
/* Temporarily drop privileged uid for mkdir/bind. */ |
| 200 |
temporarily_use_uid(pw); |
207 |
temporarily_use_uid(pw); |
| 201 |
|
208 |
|
| 202 |
/* Allocate a buffer for the socket name, and format the name. */ |
209 |
path = session_get_runtime_directory(); |
| 203 |
auth_sock_dir = xstrdup("/tmp/ssh-XXXXXXXXXX"); |
210 |
if (strcmp(path, "/tmp") == 0) { |
| 204 |
|
211 |
/* Allocate a buffer for the socket name, and format the name. */ |
| 205 |
/* Create private directory for socket */ |
212 |
auth_sock_dir = xstrdup("/tmp/ssh-XXXXXXXXXX"); |
| 206 |
if (mkdtemp(auth_sock_dir) == NULL) { |
213 |
|
| 207 |
packet_send_debug("Agent forwarding disabled: " |
214 |
/* Create private directory for socket */ |
| 208 |
"mkdtemp() failed: %.100s", strerror(errno)); |
215 |
if (mkdtemp(auth_sock_dir) == NULL) { |
| 209 |
restore_uid(); |
216 |
packet_send_debug("Agent forwarding disabled: " |
| 210 |
free(auth_sock_dir); |
217 |
"mkdtemp() failed: %.100s", strerror(errno)); |
| 211 |
auth_sock_dir = NULL; |
218 |
restore_uid(); |
| 212 |
goto authsock_err; |
219 |
free(auth_sock_dir); |
|
|
220 |
auth_sock_dir = NULL; |
| 221 |
goto authsock_err; |
| 222 |
} |
| 223 |
free(path); |
| 224 |
} else { |
| 225 |
/* This is already private directory */ |
| 226 |
auth_sock_dir = path; |
| 227 |
remove_auth_sock_dir = 0; |
| 213 |
} |
228 |
} |
| 214 |
|
229 |
|
| 215 |
xasprintf(&auth_sock_name, "%s/agent.%ld", |
230 |
xasprintf(&auth_sock_name, "%s/agent.%ld", |
|
Lines 236-242
auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw)
Link Here
|
| 236 |
authsock_err: |
251 |
authsock_err: |
| 237 |
free(auth_sock_name); |
252 |
free(auth_sock_name); |
| 238 |
if (auth_sock_dir != NULL) { |
253 |
if (auth_sock_dir != NULL) { |
| 239 |
rmdir(auth_sock_dir); |
254 |
if (remove_auth_sock_dir) |
|
|
255 |
rmdir(auth_sock_dir); |
| 240 |
free(auth_sock_dir); |
256 |
free(auth_sock_dir); |
| 241 |
} |
257 |
} |
| 242 |
if (sock != -1) |
258 |
if (sock != -1) |
|
Lines 259-274
display_loginmsg(void)
Link Here
|
| 259 |
sshbuf_reset(loginmsg); |
275 |
sshbuf_reset(loginmsg); |
| 260 |
} |
276 |
} |
| 261 |
|
277 |
|
|
|
278 |
char * |
| 279 |
session_get_runtime_directory(void) |
| 280 |
{ |
| 281 |
char *auth_info_file = NULL; |
| 282 |
|
| 283 |
#ifdef USE_PAM |
| 284 |
auth_info_file = sshpam_get_runtime_directory(); |
| 285 |
if (auth_info_file != NULL) |
| 286 |
return auth_info_file; |
| 287 |
#endif /* USE_PAM */ |
| 288 |
return xstrdup("/tmp"); |
| 289 |
} |
| 290 |
|
| 291 |
#define SSH_AUTH_TEMPLATE "sshauth.XXXXXXXXXXXXXXX" |
| 292 |
|
| 262 |
static void |
293 |
static void |
| 263 |
prepare_auth_info_file(struct passwd *pw, struct sshbuf *info) |
294 |
prepare_auth_info_file(struct passwd *pw, struct sshbuf *info) |
| 264 |
{ |
295 |
{ |
| 265 |
int fd = -1, success = 0; |
296 |
int fd = -1, success = 0; |
|
|
297 |
char *path = NULL; |
| 266 |
|
298 |
|
| 267 |
if (!options.expose_userauth_info || info == NULL) |
299 |
if (!options.expose_userauth_info || info == NULL) |
| 268 |
return; |
300 |
return; |
| 269 |
|
301 |
|
| 270 |
temporarily_use_uid(pw); |
302 |
temporarily_use_uid(pw); |
| 271 |
auth_info_file = xstrdup("/tmp/sshauth.XXXXXXXXXXXXXXX"); |
303 |
path = session_get_runtime_directory(); |
|
|
304 |
xasprintf(&auth_info_file, "%s/" SSH_AUTH_TEMPLATE, path); |
| 305 |
free(path); |
| 272 |
if ((fd = mkstemp(auth_info_file)) == -1) { |
306 |
if ((fd = mkstemp(auth_info_file)) == -1) { |
| 273 |
error("%s: mkstemp: %s", __func__, strerror(errno)); |
307 |
error("%s: mkstemp: %s", __func__, strerror(errno)); |
| 274 |
goto out; |
308 |
goto out; |