Example #1
0
/*----------------------------------------------------------------------
       Check if we can access a file in a given way in the given path

   Args: path     -- The path to look for "file" in
	 file      -- The file to check
         mode      -- The mode ala the access() system call, see ACCESS_EXISTS
                      and friends in alpine.h.

 Result: returns 0 if the user can access the file according to the mode,
         -1 if he can't (and errno is set).
 ----*/
int
can_access_in_path(char *path, char *file, int mode)
{
    char tmp[MAXPATH];
    int  rv = -1;

    if(!path || !*path || is_rooted_path(file)){
	rv = can_access(file, mode);
    }
    else if(is_homedir_path(file)){
	strncpy(tmp, file, sizeof(tmp));
	tmp[sizeof(tmp)-1] = '\0';
	rv = fnexpand(tmp, sizeof(tmp)) ? can_access(tmp, mode) : -1;
    }
    else if((rv = ACCESS_IN_CWD(file,mode)) < 0){
	char path_copy[MAXPATH + 1], *p, *t;

	if(strlen(path) < MAXPATH){
	    strncpy(path_copy, path, sizeof(path_copy));
	    path_copy[sizeof(path_copy)-1] = '\0';

	    for(p = path_copy; p && *p; p = t){
		if((t = strchr(p, PATH_SEP)) != NULL)
		  *t++ = '\0';

		snprintf(tmp, sizeof(tmp), "%s%c%s", p, FILE_SEP, file);
		if((rv = can_access(tmp, mode)) == 0)
		  break;
	    }
	}
    }

    return(rv);
}
Example #2
0
void renameFileProc(XtPointer fsel, int conf)
{
 SelFileNamesRec *fnames = (SelFileNamesRec *) fsel;
 struct stat stats;
 char to[MAXPATHLEN];

 if (conf != YES)
 {
     freeSelFiles(fnames);
     return;
 }
 if (chdir(fnames->directory))
 {
     sysError(fnames->shell, "System error:");
     freeSelFiles(fnames);
     return;
 }
 chdir(user.home);
 if (fnames->target[0] != '/' && fnames->target[0] != '~' && fnames->target != 0)
 {
     strcpy(to, fnames->directory);
     if (to[strlen(to)-1] != '/')  strcat(to, "/");
 }
 else to[0] = 0;
 strcat(to, fnames->target);
 fnexpand(to);
 XTFREE(fnames->target);
 fnames->target = XtNewString(to);
 if (!(stat(to, &stats)) && S_ISDIR(stats.st_mode))
     renameDialog(fnames);
 else moveFilesProc(fsel, YES);
}
Example #3
0
/*----------------------------------------------------------------------
    Check to see if user is allowed to read or write this folder.

   Args:  s  -- the name to check
 
 Result: Returns 1 if OK
         Returns 0 and posts an error message if access is denied
  ----*/
int
context_allowed(char *s)
{
    struct variable *vars = ps_global ? ps_global->vars : NULL;
    int retval = 1;
    MAILSTREAM stream; /* fake stream for error message in mm_notify */

    if(ps_global
       && ps_global->restricted
       && (strindex("./~", s[0]) || srchstr(s, "/../"))){
	stream.mailbox = s;
	mm_notify(&stream, "Restricted mode doesn't allow operation", WARN);
	retval = 0;
    }
    else if(vars && VAR_OPER_DIR
	    && s[0] != '{' && !(s[0] == '*' && s[1] == '{')
	    && strucmp(s,ps_global->inbox_name) != 0
	    && strcmp(s, ps_global->VAR_INBOX_PATH) != 0){
	char *p, *free_this = NULL;

	p = s;
	if(strindex(s, '~')){
	    p = strindex(s, '~');
	    free_this = (char *)fs_get(strlen(p) + 200);
	    strncpy(free_this, p, strlen(p)+200);
	    fnexpand(free_this, strlen(p)+200);
	    p = free_this;
	}
	else if(p[0] != '/'){  /* add home dir to relative paths */
	    free_this = p = (char *)fs_get(strlen(s)
					    + strlen(ps_global->home_dir) + 2);
	    build_path(p, ps_global->home_dir, s,
		       strlen(s)+strlen(ps_global->home_dir)+2);
	}
	
	if(!in_dir(VAR_OPER_DIR, p)){
	    char err[200];

	    /* TRANSLATORS: User is restricted to operating within a certain directory */
	    snprintf(err, sizeof(err), _("Not allowed outside of %.150s"), VAR_OPER_DIR);
	    stream.mailbox = p;
	    mm_notify(&stream, err, WARN);
	    retval = 0;
	}
	else if(srchstr(p, "/../")){  /* check for .. in path */
	    stream.mailbox = p;
	    mm_notify(&stream, "\"..\" not allowed in name", WARN);
	    retval = 0;
	}

	if(free_this)
	  fs_give((void **)&free_this);
    }
    
    return retval;
}
Example #4
0
static void iconFileViewCb(Widget w, XtPointer client_data, XtPointer call_data)
{
 AppRec *app = &((DTIconRec *) client_data)->app;
 char path[MAXPATHLEN];

 if (app->directory[0])
 {
     strcpy(path, app->directory);
     fnexpand(path);
 }
 else  strcpy(path, user.home);

 doView(path, app->fname);
}
Example #5
0
void dirOpenCb(Widget w, XtPointer client_data, XtPointer call_data)
{
 FileWindowRec *fw = (FileWindowRec *) client_data;
 char path[MAXPATHLEN];
 int item;

 zzz();
 XtVaGetValues(fw->form, XmNuserData, (XtPointer) &item, NULL);
 strcpy(path, fw->directory);
 if (path[strlen(path)-1] != '/')  strcat(path, "/");
 strcat(path, fw->files[item]->name);
 fnexpand(path);
 contractPath(path);
 newFileWindow(path, fw, NULL);
 wakeUp();
}
Example #6
0
/*
 * Add all the entries from this file onto the Mailcap list.
 */
void
mc_process_file(char *file)
{
    char filebuf[MAXPATH+1], *file_data;

    dprint((5, "mailcap: process_file: %s\n", file ? file : "?"));

    (void)strncpy(filebuf, file, MAXPATH);
    filebuf[MAXPATH] = '\0';
    file = fnexpand(filebuf, sizeof(filebuf));
    dprint((7, "mailcap: processing file: %s\n", file ? file : "?"));
    switch(is_writable_dir(file)){
      case 0: case 1: /* is a directory */
	dprint((1, "mailcap: %s is a directory, should be a file\n",
	    file ? file : "?"));
	return;

      case 2: /* ok */
	break;

      case 3: /* doesn't exist */
	dprint((5, "mailcap: %s doesn't exist\n", file ? file : "?"));
	return;

      default:
	panic("Programmer botch in mc_process_file");
	/*NOTREACHED*/
    }

    if((file_data = read_file(file, READ_FROM_LOCALE)) != NULL){
	STRINGLIST *newsl, **sl;

	/* Create a new container */
	newsl		 = mail_newstringlist();
	newsl->text.data = (unsigned char *) file_data;

	/* figure out where in the list it should go */
	for(sl = &MailcapData.raw; *sl; sl = &((*sl)->next))
	  ;

	*sl = newsl;			/* Add it to the list */

	mc_parse_file(file_data);	/* the process mailcap data */
    }
    else
      dprint((5, "mailcap: %s can't be read\n", file ? file : "?"));
}
Example #7
0
void changeDirCb(Widget w, XtPointer client_data, XtPointer calldata)
{
 FileWindowRec *fw = (FileWindowRec *) client_data;
 char *newpath, dir[MAXPATHLEN];

 newpath = XmTextFieldGetString(w);
 if (newpath[0] != '/' && newpath[0] != '~' && newpath[0] != 0)
 {
     strcpy(dir, fw->directory);
     if (dir[strlen(dir)-1] != '/')  strcat(dir, "/");
 }
 else dir[0] = 0;
 strcat(dir, newpath);
 XTFREE(newpath);
 fnexpand(dir);
 contractPath(dir);
 if (!chFileDir(fw, dir))
     XmTextFieldSetString(fw->dirfield, fw->directory);
}
Example #8
0
static void displayDTIcon(DTIconRec *dticon)
{
 XGCValues xgcv;
 GC shapeGC;
 Window shellwin;
 XmString labelstr;
 Dimension labelwidth, labelheight, togglewidth, toggleheight;
 Dimension tgl_offs_x, lbl_offs_x, lbl_offs_y;
 Atom targets[2];
 Boolean is_file = False;
 int i;

 targets[0] = dragAtoms.file;
 targets[1] = dragAtoms.filelist;
 drop_args[0].value = (XtArgVal) targets;

 dticon->app.form = XtVaCreateManagedWidget("form", xmFormWidgetClass, dticon->cont, XmNtranslations, XtParseTranslationTable(form_translations), XmNbackground, resources.dticon_color, XmNforeground, resources.label_color, XmNborderWidth, 0, XmNshadowThickness, 0, XmNhighlightThickness, 0, XmNx, 0, XmNy, 0, NULL);

 if (dticon->app.fname[0])
 {
     char path[MAXPATHLEN];
     struct stat stats;
     int errfl = 0;

     if (dticon->app.directory[0])
     {
	 strcpy(path, dticon->app.directory);
	 fnexpand(path);
	 errfl = chdir(path);
     }
     else  errfl = chdir(user.home);
     if (!errfl && !(stat(dticon->app.fname, &stats)) && S_ISREG(stats.st_mode))
	 is_file = True;
 }
 if (is_file)
 {
     for (i=0; i < XtNumber(file_popup_menu); i++)
	 file_popup_menu[i].callback_data = dticon;
     dticon->popup = BuildMenu(dticon->app.form, XmMENU_POPUP, "Button Actions", 0, False, file_popup_menu);
     if (resources.auto_save)
	 XtVaSetValues(file_popup_menu[5].object, XmNsensitive, False, NULL);
 }
 else
 {
     for (i=0; i < XtNumber(file_popup_menu); i++)
	 popup_menu[i].callback_data = dticon;
     dticon->popup = BuildMenu(dticon->app.form, XmMENU_POPUP, "Button Actions", 0, False, popup_menu);
     if (resources.auto_save)
	 XtVaSetValues(popup_menu[3].object, XmNsensitive, False, NULL);
 }

 labelstr = XmStringCreateLocalized(dticon->app.name);
 labelwidth = XmStringWidth((XmFontList) resources.icon_font, labelstr) + 2;
 togglewidth = dticon->app.icon_pm.width;
 toggleheight = dticon->app.icon_pm.height;
 if (labelwidth > togglewidth)
 {
     tgl_offs_x = (labelwidth - togglewidth) / 2;
     lbl_offs_x = 0;
 }
 else
 {
     tgl_offs_x = 0;
     lbl_offs_x = (togglewidth - labelwidth) / 2;
 }
 lbl_offs_y = dticon->app.icon_pm.height + 2;

 dticon->app.toggle = XtVaCreateManagedWidget("picture", xmLabelWidgetClass, dticon->app.form, XmNlabelType, XmPIXMAP, XmNlabelPixmap, dticon->app.icon_pm.bm, XmNtranslations, trans, XmNborderWidth, 0, XmNhighlightThickness, 0, XmNbackground, resources.dticon_color, XmNforeground, resources.label_color, XmNx, tgl_offs_x, XmNy, 0, NULL);
/*  RBW - 2001/08/15  */
XtInsertEventHandler(dticon->app.toggle,
                     EnterWindowMask|LeaveWindowMask,
                     False,
                     (XtEventHandler)CatchEntryLeave2,
                     (XtPointer)0,
                     XtListHead);

 dticon->app.label = XtVaCreateManagedWidget("label", xmLabelWidgetClass, dticon->app.form, XmNlabelString, labelstr, XmNfontList, resources.icon_font, XmNtranslations, trans, XmNbackground, resources.dticon_color, XmNforeground, resources.label_color, XmNborderWidth, 0, XmNhighlightThickness, 0, XmNx, lbl_offs_x, XmNy, lbl_offs_y, NULL);
/*  RBW - 2001/08/15  */
XtInsertEventHandler(dticon->app.label,
                     EnterWindowMask|LeaveWindowMask,
                     False,
                     (XtEventHandler)CatchEntryLeave2,
                     (XtPointer)0,
                     XtListHead);

 XmStringFree(labelstr);

 XtRealizeWidget(dticon->shell);
 shellwin = XtWindow(dticon->shell);

 XtVaGetValues(dticon->app.label, XmNwidth, &labelwidth, XmNwidth, &labelheight, NULL);
 labelheight += 2;
 dticon->label_mask = XCreatePixmap(dpy, shellwin, labelwidth, labelheight, 1);
 shapeGC = XCreateGC(dpy, dticon->label_mask, 0, &xgcv);
 XSetForeground(dpy, shapeGC, 1);
 XFillRectangle(dpy, dticon->label_mask, shapeGC, 0, 0, labelwidth, labelheight);
 XFreeGC(dpy, shapeGC);
 if (dticon->app.icon_pm.mask == None)
 {
     dticon->app.icon_pm.mask = XCreatePixmap(dpy, shellwin, dticon->app.icon_pm.width, dticon->app.icon_pm.height, 1);
     shapeGC = XCreateGC(dpy, dticon->app.icon_pm.mask, 0, &xgcv);
     XSetForeground(dpy, shapeGC, 1);
     XFillRectangle(dpy, dticon->app.icon_pm.mask, shapeGC, 0, 0, togglewidth, toggleheight);
     XFreeGC(dpy, shapeGC);
 }
 XShapeCombineMask(dpy, shellwin, ShapeBounding, tgl_offs_x + 2, 2, dticon->app.icon_pm.mask, ShapeSet);
 XShapeCombineMask(dpy, shellwin, ShapeBounding, lbl_offs_x + 2, lbl_offs_y + 2, dticon->label_mask, ShapeUnion);
 XShapeCombineMask(dpy, XtWindow(dticon->app.form), ShapeClip, tgl_offs_x + 2, 2, dticon->app.icon_pm.mask, ShapeSet);
 XShapeCombineMask(dpy, XtWindow(dticon->app.form), ShapeClip, lbl_offs_x + 2, lbl_offs_y + 2, dticon->label_mask, ShapeUnion);
 XShapeCombineMask(dpy, XtWindow(dticon->app.toggle), ShapeClip, 2, 2, dticon->app.icon_pm.mask, ShapeSet);

 XtVaGetValues(dticon->shell, XmNwidth, &dticon->width, XmNheight, &dticon->height, NULL);

 dticon->drop_pixmap = XCreatePixmap(dpy, shellwin, dticon->width, dticon->height, DefaultDepth(dpy, DefaultScreen(dpy)));
 shapeGC = XCreateGC(dpy, dticon->drop_pixmap, 0, &xgcv);
 XSetForeground(dpy, shapeGC, resources.drop_color);
 XFillRectangle(dpy, dticon->drop_pixmap, shapeGC, 0, 0, dticon->width, dticon->height);
 XFreeGC(dpy, shapeGC);
 drop_args[4].value = (XtArgVal) dticon->drop_pixmap;

 if (dticon->app.drop_action[0])
     XmDropSiteRegister(dticon->app.form, drop_args, XtNumber(drop_args));

}
Example #9
0
void moveFilesProc(XtPointer fsel, int conf)
{
 SelFileNamesRec *fnames = (SelFileNamesRec *) fsel;
 struct stat tostats, tolstats, frstats;
 char from[MAXPATHLEN], to[MAXPATHLEN];
 String name, cwd;
 String op_name, from_err, to_err;
 size_t toend, fromend;
 int devto, devfrom, deverr = -1, i, perm, res;
 Boolean is_dir, is_link;

 if (conf != YES || !fnames->op)
 {
     freeSelFiles(fnames);
     return;
 }
 if (chdir(fnames->directory))
 {
     sysError(fnames->shell, "System error:");
     freeSelFiles(fnames);
     return;
 }
 chdir(user.home);
 switch (fnames->op)
 {
     case COPY:
	 op_name = "Copy:";
	 from_err = "Error copying";
	 to_err = "Error copying to";
	 break;
     case MOVE:
	 op_name = "Move:";
	 from_err = "Error moving";
	 to_err = "Error moving to";
	 break;
     default:  /* i.e. LINK */
	 op_name = "Link:";
	 from_err = "Error creating symlink to";
	 to_err = "Error creating symlink in";
 }
 if (fnames->target[0] != '/' && fnames->target[0] != '~' && fnames->target != 0)
 {
     strcpy(to, fnames->directory);
     if (to[strlen(to)-1] != '/')  strcat(to, "/");
 }
 else to[0] = 0;
 strcat(to, fnames->target);
 fnexpand(to);
 if (!(cwd = absolutePath(to)))
 {
     error(fnames->shell, no_target, to);
     freeSelFiles(fnames);
     return;
 }
 strcpy(to, cwd);
 XTFREE(cwd);
 fromend = strlen(strcpy(from, fnames->directory));
 if (from[fromend-1] != '/')
 {
     from[fromend++] = '/';
     from[fromend] = 0;
 }
 devfrom = findDev(from);
 if (mountDev(devto = findDev(to), False))
     deverr = devto;
 else if (mountDev(devfrom, False))
     deverr = devfrom;
 if (deverr != -1)
 {
     error(fnames->shell, "Cannot mount device on", mntable.devices[deverr].def_mpoint);
     umountDev(devto, False);
     freeSelFiles(fnames);
     return;
 }
 if (!(stat(to, &tostats)) && S_ISDIR(tostats.st_mode))
 {
     if (chdir(to) || !(perm = permission(&tostats, P_WRITE)))
     {
	 chdir(user.home);
	 if (!perm)
	     error(fnames->shell, "You have no write permission for ", to);
	 else  sysError(fnames->shell, "System error:");
	 umountDev(devto, False);
	 umountDev(devfrom, False);
	 freeSelFiles(fnames);
	 return;
     }
     chdir(user.home);
     fnames->dirtarget = True;
     toend = strlen(to);
     if (to[toend-1] != '/')
     {
	 to[toend++] = '/';
	 to[toend] = 0;
     }
 }
 else if (fnames->n_sel == 1)  fnames->dirtarget = False;
 else
 {
     error(fnames->shell, op_name, "Target for multiple files must be a folder");
     umountDev(devto, False);
     umountDev(devfrom, False);
     freeSelFiles(fnames);
     return;
 }
 if (!fnames->first)  zzz();
 XTFREE(fnames->target);
 fnames->target = XtNewString(to);
 for (i = fnames->first; i < fnames->n_sel; i++)
 {
     name = fnames->names[i];
     if (fnames->op != LINK && (!strcmp(name, ".") || !strcmp(name, "..")))
     {
	 error(fnames->shell, "Cannot move or copy . or ..", NULL);
	 continue;
     }
     strcpy(from+fromend, name);
     if (fnames->dirtarget)
     {
	 if (fnames->op != LINK && prefix(from, to))
	 {
	     String err_str, format = "Cannot move or copy %s to";
	     err_str = (String) XtMalloc((strlen(format) + strlen(from)) * sizeof(char));
	     sprintf(err_str, format, from);
	     error(fnames->shell, err_str, to);
	     XTFREE(err_str);
	     umountDev(devto, False);
	     umountDev(devfrom, False);
	     freeSelFiles(fnames);
	     wakeUp();
	     return;
	 }
	 strcpy(to+toend, name);
     }
     if (!(lstat(to, &tolstats)))
     {
	 fnames->first = i;
	 is_dir = False;
	 if (!(stat(to, &tostats)))
	 {
	     if (S_ISDIR(tostats.st_mode))
		 is_dir = True;
	     if (!stat(from, &frstats) && tostats.st_ino == frstats.st_ino)
	     {
		 error(fnames->shell, op_name, "Source and destination are identical");
		 umountDev(devto, False);
		 umountDev(devfrom, False);
		 freeSelFiles(fnames);
		 wakeUp();
		 return;
	     }
	 }
	 if (S_ISLNK(tolstats.st_mode))
	     is_link = True;
	 else  is_link = False;

	 if (fnames->conf_ovwr || (is_dir && (!is_link || fnames->op == COPY) && resources.confirm_delete_folder))
	     overwriteDialog(fnames, to, (fnames->op == COPY && is_dir && (lstat(from, &frstats) || !S_ISDIR(frstats.st_mode)))?
			     "File copy:" : op_name,
			     is_dir && (!is_link || fnames->op == COPY));
	 else overwriteProc(fsel, YES);
	 umountDev(devto, False);
	 umountDev(devfrom, False);
	 return;
     }
     switch (fnames->op)
     {
	 case COPY:	rcopy(from, to, False); res = 0; break;
	 case MOVE:	res = movefile(from, to); break;
	 default:	res = makeLink(from, to);
     }
     if (res)
     {
	 if (opError(fnames->shell, from_err, name) != YES)
	     break;
     }
     else  fnames->update = True;
 }
 umountDev(devto, False);
 umountDev(devfrom, False);
 if (fnames->update)
 {
     if (fnames->op == COPY)
	 intUpdate(CHECK_DIR);		/* Check for new subdirectories */
     if (fnames->op == MOVE)
	 markForUpdate(fnames->directory, CHECK_FILES);
     markForUpdate(to, RESHOW);
     if (fnames->op != COPY)
	 intUpdate(CHECK_DIR);
 }
 freeSelFiles(fnames);
 wakeUp();
}