www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to make a directory?

reply "Minas" <minas_mina1990 hotmail.co.uk> writes:
What is the D way to create a directory?

I can use the C function system("mkdir ...") but it doesn't seem 
very good to me.

Also, is there a way to require the root password of the user 
when going create the directory in a restricted folder (like 
/usr) AFTER the application has started?

Thank you.
May 01 2012
next sibling parent =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 02-05-2012 01:45, Minas wrote:
 What is the D way to create a directory?

 I can use the C function system("mkdir ...") but it doesn't seem very
 good to me.

It's not in the most obvious of places: http://dlang.org/phobos/std_file.html#mkdir (But then again, an std.directory module would probably be a bit overkill...)
 Also, is there a way to require the root password of the user when going
 create the directory in a restricted folder (like /usr) AFTER the
 application has started?

No idea, sorry.
 Thank you.

-- - Alex
May 01 2012
prev sibling next sibling parent Kevin Cox <kevincox.ca gmail.com> writes:
--0015175cf89e5eaf5f04bf0273dc
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On May 1, 2012 7:49 PM, "Alex R=C3=B8nne Petersen" <xtzgzorex gmail.com> wr=
ote:
 Also, is there a way to require the root password of the user when going
 create the directory in a restricted folder (like /usr) AFTER the
 application has started?

No idea, sorry.
 Thank you.

-- - Alex

You could execute a system command and change your apps privileges but this is a bad/risky way to do it. I would use sudo or gksudo and launch the command externally so that you don't grant your app root permissions and then do something stupid. If those actions are common I would only allow root to use your app. --0015175cf89e5eaf5f04bf0273dc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p><br> On May 1, 2012 7:49 PM, &quot;Alex R=C3=B8nne Petersen&quot; &lt;<a href=3D= "mailto:xtzgzorex gmail.com">xtzgzorex gmail.com</a>&gt; wrote:<br> &gt;&gt;<br> &gt;&gt; Also, is there a way to require the root password of the user when= going<br> &gt;&gt; create the directory in a restricted folder (like /usr) AFTER the<= br> &gt;&gt; application has started?<br> &gt;<br> &gt;<br> &gt; No idea, sorry.<br> &gt;<br> &gt;&gt;<br> &gt;&gt; Thank you.<br> &gt;<br> &gt;<br> &gt; -- <br> &gt; - Alex</p> <p>You could execute a system command and change your apps privileges but t= his is a bad/risky way to do it.=C2=A0 I would use sudo or gksudo and launc= h the command externally so that you don&#39;t grant your app root permissi= ons and then do something stupid.=C2=A0 If those actions are common I would= only allow root to use your app.<br> </p> --0015175cf89e5eaf5f04bf0273dc--
May 01 2012
prev sibling parent Jordi Sayol <g.sayol yahoo.es> writes:
Al 02/05/12 01:45, En/na Minas ha escrit:
[...]
 Also, is there a way to require the root password of the user when going
create the directory in a restricted folder (like /usr) AFTER the application
has started?

In Linux, files and directories have the "setuid" and "setgid" special flags that allow ordinary users to execute binaries with temporary privileges of binary file owner or group. i.e., /usr/bin/passwd (owns root, with setuid) modifies /etc/passwd by any user without write permission. /bin/ping (owns root, with setuid) allows any user to send and listen control packages throw net interfaces. -- Jordi Sayol
May 01 2012