Subject: Restricted Pico ?

From: [email-masked] (Alina Bartsch)
Date: 5 Jun 1995 12:15:10 GMT

I will use the eitor pico in a application.
I will that the user cannot change the filename (is an parameter)
an not use the file browser.
Could I define this in the environment or as parameters?

---

From: [email-masked] (David Drum)
Date: 13 Jun 1995 17:29:18 GMT

Alina Bartsch ([email-masked]) wrote:
: I will use the eitor pico in a application.
: I will that the user cannot change the filename (is an parameter)
: an not use the file browser.
: Could I define this in the environment or as parameters?

You have to edit the source code.  Use "pico -r filename".  Here is the patch:

Regards,

David
[email-masked]

#####Patch 1####################################################################
diff -crw pine3.91/pico/main.c spine3.91/pico/main.c
*** pine3.91/pico/main.c        Mon Sep 12 13:32:15 1994
--- spine3.91/pico/main.c       Wed Apr  5 09:24:39 1995
***************
*** 138,143 ****
--- 138,146 ----
              case 'w':                 /* -w turn off word wrap */
                gmode ^= MDWRAP;
                break;
+ /*APG*/             case 'r':                 /* -r keep users from editing filename or getting out of work directory */
+ /*APG*/               gmode ^= MDSCUR;
+ /*APG*/               break;
  #if   defined(DOS)
              case 'c':                 /* -c[nr][fb] colors */
                if(carg + 1 < argc){
diff -crw pine3.91/pico/file.c spine3.91/pico/file.c
*** pine3.91/pico/file.c        Tue Oct 11 18:47:07 1994
--- spine3.91/pico/file.c       Wed Jun  7 14:48:02 1995
***************
*** 332,343 ****
        else
          fname[0] = '\0';

        menu_write[0].name  = "^T";
        menu_write[0].label = "To Files";
        menu_write[1].name  = NULL;
        for(;;){
!           s = mlreplyd("File Name to write : ", fname, NFILEN,
!                        QDEFLT|QFFILE, menu_write);

            fixpath(fname, NFILEN);             /*  fixup ~ in file name  */

--- 338,354 ----
        else
          fname[0] = '\0';

+ /*APG*/       if (gmode&MDSCUR)
+ /*APG*/           menu_write[0].name  = NULL;
+ /*APG*/       else {
            menu_write[0].name  = "^T";
            menu_write[0].label = "To Files";
            menu_write[1].name  = NULL;
+ /*APG*/       } /* else */
        for(;;){
! /*APG*/           if (!(gmode&MDSCUR))
!               s = mlreplyd("File Name to write : ", fname, NFILEN, QDEFLT|QFFILE, menu_write);
! /*APG*/           else s = TRUE;

            fixpath(fname, NFILEN);             /*  fixup ~ in file name  */
################################################################################

However, this may restrict things more than you want.  Here are some optional
patches:

#####Patch 2####################################################################
diff -crw pine3.91/pico/browse.c spine3.91/pico/browse.c
*** pine3.91/pico/browse.c      Tue Sep 27 11:19:48 1994
--- spine3.91/pico/browse.c     Mon Apr  3 17:46:04 1995
***************
*** 466,472 ****
                break;
            }

!           if(gmode&MDSCUR){                           /* not allowed! */
                emlwrite("Delete not allowed in restricted mode",NULL);
                break;
            }
--- 466,472 ----
                break;
            }

! /*APG*/           if ((gmode&MDSCUR) && homeless (gmp->current->fname)) {
                emlwrite("Delete not allowed in restricted mode",NULL);
                break;
            }
***************
*** 576,582 ****
                        break;
                    }

!                   if((gmode&MDSCUR) && homeless(child)){
                        emlwrite("Restricted mode browsing limited to home directory",NULL);
                        break;
                    }
--- 576,582 ----
                        break;
                    }

! /*APG*/                   if((gmode&MDSCUR) && homeless(child)){
                        emlwrite("Restricted mode browsing limited to home directory",NULL);
                        break;
                    }
***************
*** 610,616 ****
                break;
            }

!           if(gmode&MDSCUR){                           /* not allowed! */
                emlwrite("Copy not allowed in restricted mode",NULL);
                break;
            }
--- 610,616 ----
                break;
            }

! /*APG*/           if ((gmode&MDSCUR) && homeless (gmp->current->fname)) {
                emlwrite("Copy not allowed in restricted mode",NULL);
                break;
            }
***************
*** 654,659 ****
--- 654,664 ----
                    strcpy(tmp, child);                 /* add full path! */
                    sprintf(child, "%s%c%s", gmp->dname, C_FILESEP, tmp);

+ /*APG*/                   if ((gmode&MDSCUR) && homeless (gmp->current->fname)) {
+ /*APG*/                       emlwrite("Make Copy not allowed outside of home directory",NULL);
+ /*APG*/                       break;
+ /*APG*/                   }
+ /*APG*/
                    if((status = fexist(child, "w", (long *)NULL)) == FIOSUC){
                        sprintf(tmp,"File \"%.*s\" exists! OVERWRITE",
                                NLINE - 20, child);
***************
*** 726,732 ****
                break;
            }

!           if(gmode&MDSCUR){                           /* not allowed! */
                emlwrite("Rename not allowed in restricted mode",NULL);
                break;
            }
--- 731,737 ----
                break;
            }

! /*APG*/           if ((gmode&MDSCUR) && homeless (gmp->current->fname)) {
                emlwrite("Rename not allowed in restricted mode",NULL);
                break;
            }
***************
*** 758,763 ****
--- 763,773 ----

                    strcpy(tmp, child);
                    sprintf(child, "%s%c%s", gmp->dname, C_FILESEP, tmp);
+ /*APG*/
+ /*APG*/                   if ((gmode&MDSCUR) && homeless (gmp->current->fname)) {
+ /*APG*/                       emlwrite("Rename not allowed outside of home directory",NULL);
+ /*APG*/                       break;
+ /*APG*/                   }

                    status = fexist(child, "w", (long *)NULL);
                    if(status == FIOSUC || status == FIOFNF){
diff -crw pine3.91/pico/file.c spine3.91/pico/file.c
*** pine3.91/pico/file.c        Tue Oct 11 18:47:07 1994
--- spine3.91/pico/file.c       Wed Jun  7 14:48:02 1995
***************
*** 77,86 ****
          if ((s=mlreply("Read file: ", fname, NFILEN, QNORML, NULL)) != TRUE)
                  return(s);

!       if(gmode&MDSCUR){
!           emlwrite("File reading disabled in secure mode",NULL);
!           return(0);
!       }

        if (strlen(fname) == 0) {
          emlwrite("No file name entered",NULL);
--- 77,88 ----
          if ((s=mlreply("Read file: ", fname, NFILEN, QNORML, NULL)) != TRUE)
                  return(s);

! /*APG
!   APG if(gmode&MDSCUR){
!   APG     emlwrite("File reading disabled in secure mode",NULL);
!   APG     return(0);
!   APG }
!   APG*/

        if (strlen(fname) == 0) {
          emlwrite("No file name entered",NULL);
***************
*** 163,178 ****

                    fname[0] = '\0';
                    if((s = FileBrowse(dir, fname, NULL, FB_READ)) == 1){
!                       if(gmode&MDSCUR){
!                           emlwrite("Can't insert file in restricted mode",
!                                    NULL);
!                           sleep(2);
!                       }
!                       else{
!                           strcat(dir, S_FILESEP);
                            strcat(dir, fname);
                            retval = ifile(dir);
!                       }
                        bye++;
                    }
                    else
--- 165,183 ----

                    fname[0] = '\0';
                    if((s = FileBrowse(dir, fname, NULL, FB_READ)) == 1){
! /*APG*
!  *APG*                        if(gmode&MDSCUR){
!  *APG*                            emlwrite("Can't insert file in restricted mode",
!  *APG*                                     NULL);
!  *APG*                            sleep(2);
!  *APG*                        }
!  *APG*                        else{
!  *APG*/                           strcat(dir, S_FILESEP);
                            strcat(dir, fname);
                            retval = ifile(dir);
! /*APG*
!  *APG*                        }
!  *APG*/
                        bye++;
                    }
                    else
***************
*** 202,208 ****
              }
              else{
                bye++;
!               if(gmode&MDSCUR){
                    emlwrite("Can't insert file in restricted mode",NULL);
                }
                else{
--- 207,214 ----
              }
              else{
                bye++;
! /*APG*/               compresspath (gethomedir(NULL), fname, NFILEN);
! /*APG*/               if((gmode&MDSCUR) && homeless (fname)){
                    emlwrite("Can't insert file in restricted mode",NULL);
                }
                else{
***************
*** 397,402 ****
--- 408,418 ----

            if(strcmp(fname, curbp->b_fname) == 0)
                break;
+ /*APG*/
+ /*APG*/           if((gmode&MDSCUR) && homeless (fname)) {
+ /*APG*/               emlwrite("Can't write file outside home directory in secure mode",NULL);
+ /*APG*/               return(s);
+ /*APG*/           };

            if((s=fexist(fname, "w", &l)) == FIOSUC){ /* exists.  overwrite? */

diff -crw pine3.91/pico/os_unix.c spine3.91/pico/os_unix.c
*** pine3.91/pico/os_unix.c     Mon Oct 10 18:28:57 1994
--- spine3.91/pico/os_unix.c    Tue Jun 13 12:17:44 1995
***************
*** 538,547 ****
      if(Pmaster == NULL)
        return(-1);

!     if(gmode&MDSCUR){
!       emlwrite("Alternate editor not available in restricted mode", NULL);
!       return(-1);
!     }

      if(Pmaster->alt_ed == NULL){
        if(!(gmode&MDADVN)){
--- 538,549 ----
      if(Pmaster == NULL)
        return(-1);

! /*APG*
!  *APG*    if(gmode&MDSCUR){
!  *APG*        emlwrite("Alternate editor not available in restricted mode", NULL);
!  *APG*        return(-1);
!  *APG*    }
!  *APG*/

      if(Pmaster->alt_ed == NULL){
        if(!(gmode&MDADVN)){
################################################################################
--
"That man has a rare gift for obfuscation." -- ST:DS9