smrsh.c (105016) | smrsh.c (110563) |
---|---|
1/* 2 * Copyright (c) 1998-2002 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1993 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * | 1/* 2 * Copyright (c) 1998-2002 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1993 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * |
12 * $FreeBSD: head/contrib/sendmail/smrsh/smrsh.c 105016 2002-10-13 00:56:58Z gshapiro $ | 12 * $FreeBSD: head/contrib/sendmail/smrsh/smrsh.c 110563 2003-02-08 20:35:51Z gshapiro $ |
13 * 14 */ 15 16#include <sm/gen.h> 17 18SM_IDSTR(copyright, 19"@(#) Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.\n\ 20 All rights reserved.\n\ 21 Copyright (c) 1993 Eric P. Allman. All rights reserved.\n\ 22 Copyright (c) 1993\n\ 23 The Regents of the University of California. All rights reserved.\n") 24 | 13 * 14 */ 15 16#include <sm/gen.h> 17 18SM_IDSTR(copyright, 19"@(#) Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.\n\ 20 All rights reserved.\n\ 21 Copyright (c) 1993 Eric P. Allman. All rights reserved.\n\ 22 Copyright (c) 1993\n\ 23 The Regents of the University of California. All rights reserved.\n") 24 |
25SM_IDSTR(id, "@(#)$Id: smrsh.c,v 8.58 2002/05/25 02:41:31 ca Exp $") | 25SM_IDSTR(id, "@(#)$Id: smrsh.c,v 8.58.2.2 2002/09/24 21:40:05 ca Exp $") |
26 27/* 28** SMRSH -- sendmail restricted shell 29** 30** This is a patch to get around the prog mailer bugs in most 31** versions of sendmail. 32** 33** Use this in place of /bin/sh in the "prog" mailer definition --- 253 unchanged lines hidden (view full) --- 287 ** Check to see if the command name is legal. 288 */ 289 290 if (sm_strlcpyn(cmdbuf, sizeof cmdbuf, 3, CMDDIR, 291 "/", cmd) >= sizeof cmdbuf) 292 { 293 /* too long */ 294 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, | 26 27/* 28** SMRSH -- sendmail restricted shell 29** 30** This is a patch to get around the prog mailer bugs in most 31** versions of sendmail. 32** 33** Use this in place of /bin/sh in the "prog" mailer definition --- 253 unchanged lines hidden (view full) --- 287 ** Check to see if the command name is legal. 288 */ 289 290 if (sm_strlcpyn(cmdbuf, sizeof cmdbuf, 3, CMDDIR, 291 "/", cmd) >= sizeof cmdbuf) 292 { 293 /* too long */ 294 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, |
295 "%s: %s not available for sendmail programs (filename too long)\n", | 295 "%s: \"%s\" not available for sendmail programs (filename too long)\n", |
296 prg, cmd); 297 if (p != NULL) 298 *p = ' '; 299#ifndef DEBUG | 296 prg, cmd); 297 if (p != NULL) 298 *p = ' '; 299#ifndef DEBUG |
300 syslog(LOG_CRIT, "uid %d: attempt to use %s (filename too long)", | 300 syslog(LOG_CRIT, "uid %d: attempt to use \"%s\" (filename too long)", |
301 (int) getuid(), cmd); 302#endif /* ! DEBUG */ 303 exit(EX_UNAVAILABLE); 304 } 305 306#ifdef DEBUG 307 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, 308 "Trying %s\n", cmdbuf); 309#endif /* DEBUG */ 310 if (stat(cmdbuf, &st) < 0) 311 { 312 /* can't stat it */ 313 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, | 301 (int) getuid(), cmd); 302#endif /* ! DEBUG */ 303 exit(EX_UNAVAILABLE); 304 } 305 306#ifdef DEBUG 307 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, 308 "Trying %s\n", cmdbuf); 309#endif /* DEBUG */ 310 if (stat(cmdbuf, &st) < 0) 311 { 312 /* can't stat it */ 313 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, |
314 "%s: %s not available for sendmail programs (stat failed)\n", | 314 "%s: \"%s\" not available for sendmail programs (stat failed)\n", |
315 prg, cmd); 316 if (p != NULL) 317 *p = ' '; 318#ifndef DEBUG | 315 prg, cmd); 316 if (p != NULL) 317 *p = ' '; 318#ifndef DEBUG |
319 syslog(LOG_CRIT, "uid %d: attempt to use %s (stat failed)", | 319 syslog(LOG_CRIT, "uid %d: attempt to use \"%s\" (stat failed)", |
320 (int) getuid(), cmd); 321#endif /* ! DEBUG */ 322 exit(EX_UNAVAILABLE); 323 } 324 if (!S_ISREG(st.st_mode) 325#ifdef S_ISLNK 326 && !S_ISLNK(st.st_mode) 327#endif /* S_ISLNK */ 328 ) 329 { 330 /* can't stat it */ 331 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, | 320 (int) getuid(), cmd); 321#endif /* ! DEBUG */ 322 exit(EX_UNAVAILABLE); 323 } 324 if (!S_ISREG(st.st_mode) 325#ifdef S_ISLNK 326 && !S_ISLNK(st.st_mode) 327#endif /* S_ISLNK */ 328 ) 329 { 330 /* can't stat it */ 331 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, |
332 "%s: %s not available for sendmail programs (not a file)\n", | 332 "%s: \"%s\" not available for sendmail programs (not a file)\n", |
333 prg, cmd); 334 if (p != NULL) 335 *p = ' '; 336#ifndef DEBUG | 333 prg, cmd); 334 if (p != NULL) 335 *p = ' '; 336#ifndef DEBUG |
337 syslog(LOG_CRIT, "uid %d: attempt to use %s (not a file)", | 337 syslog(LOG_CRIT, "uid %d: attempt to use \"%s\" (not a file)", |
338 (int) getuid(), cmd); 339#endif /* ! DEBUG */ 340 exit(EX_UNAVAILABLE); 341 } 342 if (access(cmdbuf, X_OK) < 0) 343 { 344 /* oops.... crack attack possiblity */ 345 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, | 338 (int) getuid(), cmd); 339#endif /* ! DEBUG */ 340 exit(EX_UNAVAILABLE); 341 } 342 if (access(cmdbuf, X_OK) < 0) 343 { 344 /* oops.... crack attack possiblity */ 345 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, |
346 "%s: %s not available for sendmail programs\n", | 346 "%s: \"%s\" not available for sendmail programs\n", |
347 prg, cmd); 348 if (p != NULL) 349 *p = ' '; 350#ifndef DEBUG | 347 prg, cmd); 348 if (p != NULL) 349 *p = ' '; 350#ifndef DEBUG |
351 syslog(LOG_CRIT, "uid %d: attempt to use %s", | 351 syslog(LOG_CRIT, "uid %d: attempt to use \"%s\"", |
352 (int) getuid(), cmd); 353#endif /* ! DEBUG */ 354 exit(EX_UNAVAILABLE); 355 } 356 357 /* 358 ** Create the actual shell input. 359 */ --- 79 unchanged lines hidden --- | 352 (int) getuid(), cmd); 353#endif /* ! DEBUG */ 354 exit(EX_UNAVAILABLE); 355 } 356 357 /* 358 ** Create the actual shell input. 359 */ --- 79 unchanged lines hidden --- |