# # openssh-4.3p1-sshjail.patch # code by Gonçalo Silva # # tar -zxvf openssh-x.xpx.tar.gz # patch -p0 < openssh-x.xpx-sshjail.patch # # More information on http://paradigma.pt/~gngs/sshjail # --- openssh-4.3p1/session.c 2005-12-24 03:59:12.000000000 +0000 +++ openssh-4.3p1-sshjail/session.c 2006-02-04 19:33:26.000000000 +0000 @@ -59,6 +59,10 @@ #include "kex.h" #include "monitor_wrap.h" +#define SSHJAIL +#define CONF "/etc/sshjail.conf" +#define MAXLINE 512 + #if defined(KRB5) && defined(USE_AFS) #include #endif @@ -1251,6 +1255,14 @@ void do_setusercontext(struct passwd *pw) { + +#ifdef SSHJAIL + FILE *confile; + struct group *grp; + char *envchroot='\0', *username, *mypt, *line; + u_short found = 0; +#endif /* SSHJAIL */ + #ifndef HAVE_CYGWIN if (getuid() == 0 || geteuid() == 0) #endif /* HAVE_CYGWIN */ @@ -1319,6 +1331,67 @@ do_pam_setcred(0); } # endif /* USE_PAM */ + +#ifdef SSHJAIL + line = (char *)xmalloc (MAXLINE); + if ((confile = fopen(CONF, "r")) != NULL) + { + while (!feof(confile) && !found) + if (fgets(line,MAXLINE,confile)!=NULL) + { + if (strstr(line,"chroot=") && line[0]!='#') + { + envchroot=xstrdup(line+7); + envchroot[strlen(envchroot)-1]='\0'; + } + + else if (strstr(line,"users=") && line[0]!='#') + { + line += 6; + username=strtok_r(line,",",&mypt); + while(username) + { + if (username[strlen(username+1)]=='\n') + username[strlen(username+1)]='\0'; + if (username[0]=='@') + { + username += 1; + if((grp = getgrnam(username))!= NULL) + { + + if (grp->gr_gid == pw->pw_gid) + { + found=1; + break; + } + } + } + + else if (!strcmp(pw->pw_name,username)) + { + found=1; + break; + } + username=strtok_r(NULL,",",&mypt); + } + line -=6; + } + + } + + fclose(confile); + xfree(line); + } + + if (found && *envchroot!='\0') + { + if(chroot(envchroot) != 0) + fatal("Fail to chroot dir %s",envchroot); + strcpy(pw->pw_dir,pw->pw_dir+(strlen(envchroot))); + xfree(envchroot); + } +#endif /* SSHJAIL */ + # if defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) irix_setusercontext(pw); # endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */ --- openssh-4.3p1/version.h 2006-02-01 11:27:31.000000000 +0000 +++ openssh-4.3p1-sshjail/version.h 2006-02-04 19:40:38.000000000 +0000 @@ -1,6 +1,6 @@ /* $OpenBSD: version.h,v 1.46 2006/02/01 11:27:22 markus Exp $ */ -#define SSH_VERSION "OpenSSH_4.3" +#define SSH_VERSION "OpenSSH_4.3-sshjail" #define SSH_PORTABLE "p1" #define SSH_RELEASE SSH_VERSION SSH_PORTABLE