<div dir="ltr"><span style="font-family:monospace,monospace">Hello -<br><br>I would like to make my Ur server interact in a few basic ways with the Linux filesystem:<br><br>- writing files<br>- creating directories<br><br>In order to ensure security, these kinds of filesystem operations performed by Ur/Web would of course be tightly restricted to a very small predetermined set of functions, arguments, and filesystem locations, and would only be able to be directly invoked from the server-side (never from the client-side).<br><br>Since Ur is specialized to be a webserver, I don't think there are any existing commands in Ur itself which would allow the server to perform these interactions with the filesystem, correct?<br><br>So I assume this would only doable via the C FFI (foreign function interface) using C functions such as:<br><br>- fputs in stdio.h<br>- mkdir in sys/stat.h<br><br>The parameter and return types for functions operating on strings in C (such as fgets and fputs) look like:<br><br>char *<br><br>but I understand that in the ffi.c file, I would use the corresponding string type defined in urweb/urweb.h, ie:<br><br>uw_Basis_string<br><br>Is that correct?<br><br>I got some ideas from here:<br><br><a href="https://github.com/doublec/urweb-persona/blob/master/ffi.c">https://github.com/doublec/urweb-persona/blob/master/ffi.c</a><br><br>Thanks for any pointers if I'm doing anything wrong here.<br><br>===<br>===<br><br>Below are the 3 files I would plan on using:<br><br>// (1) This file is: uw_filesystem.urs<br><br>#include <urweb/urweb.h><br><br>int uw_mkdir_rwxog(uw_Basis_string);<br><br>int uw_fputs(uw_Basis_string, uw_Basis_string);<br><br>===<br>===<br><br>// (2) This file is: uw_filesystem.h<br><br>#include <urweb/urweb.h><br><br>int uw_mkdir_rwxog(uw_Basis_string);<br><br>int uw_fputs(uw_Basis_string);<br><br>===<br>===<br><br>// (3) This file is: uw_filesystem.c<br><br>#include <string.h><br>#include <sys/stat.h><br>#include <stdio.h><br>#include "ffi.h"<br><br>// create a directory, defaulting to read/write/execute persmissions for owner and group<br>// arguments: aPathName<br>// argument 'mode' (of type bit-field), representing permissions, defaults to S_IRWXU | S_IRWXG = 0770<br>// meaning read/write/search/execute permissions by owner and by group<br>// <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/mkdir.html">http://pubs.opengroup.org/onlinepubs/009695399/functions/mkdir.html</a><br>// <a href="http://pubs.opengroup.org/onlinepubs/9699919799//basedefs/sys_stat.h.html">http://pubs.opengroup.org/onlinepubs/9699919799//basedefs/sys_stat.h.html</a><br>// <a href="https://www.google.com/?gws_rd=ssl#q=c+%22bit+field%22+gcc+int+signed">https://www.google.com/?gws_rd=ssl#q=c+%22bit+field%22+gcc+int+signed</a><br>int uw_mkdir_rwxog(uw_Basis_string aPathName)<br>{<br>  int status;<br>  status = mkdir(aPathName, S_IRWXU | S_IRWXG);<br>  return (status);<br>}<br><br>// write a string to a file<br>// arguments: aFileName, aString<br>// returns: number of characters written, or EOF for error<br>int uw_fputs(uw_Basis_string aFileName, uw_Basis_string aString)<br>{<br>  FILE *fp;<br>  int status;<br>  fp = fopen(aFileName, "w");<br>  status = fputs(aString, fp);<br>  fclose(fp);<br>  return (status);<br>}<br><br>////<br><br></span></div>