Bei der Gruppe, für die Sie eine Mitteilung verfassen, handelt es sich um eine Usenet-Gruppe. Wenn Sie in dieser Gruppe Nachrichten posten, ist Ihre E-Mail-Adresse für jeden im Internet sichtbar
> In article <iVTQb.26071$1e.1...@newsread2.news.pas.earthlink.net>, Alan > Connor wrote: >> On Sun, 25 Jan 2004 12:46:12 -0500, Buck Turgidson <jc...@hotmail.com> wrote:
>>>> alias home='rm -rf $HOME'
>>> I tried this, but it didn't take me to my home directory....
>> That's really baffling.
>> I'd su to another user on your system and try again.
> When something doesn't work as you expected, always try as root! It might > be a permission problem :)
eek! no, bad idea!
What if it does something you *don't* want root to do?
better to strace it and see, rather than run it as root.
On Sun, 25 Jan 2004 12:58:34 -0800, Jim Richardson wrote: > On Sun, 25 Jan 2004 19:47:41 GMT, > Juha Siltala <jsilt...@gmx.net> wrote: >> In article <iVTQb.26071$1e.1...@newsread2.news.pas.earthlink.net>, Alan >> Connor wrote: >>> On Sun, 25 Jan 2004 12:46:12 -0500, Buck Turgidson <jc...@hotmail.com> >>> wrote: >>>>> alias home='rm -rf $HOME'
>>>> I tried this, but it didn't take me to my home directory....
>>> That's really baffling.
>>> I'd su to another user on your system and try again.
>> When something doesn't work as you expected, always try as root! It >> might be a permission problem :)
> eek! no, bad idea!
> What if it does something you *don't* want root to do?
> better to strace it and see, rather than run it as root.
"Am I putting him on or is he putting me on?" -Lloyd Fellowes (Michael Caine) in _Noises Off_
Em Sun, 25 Jan 2004 17:42:55 +0000, Albert van der Horst escreveu:
> I miss the configure script, the Makefile and man file. > An rpm would be nice too. > Also this program doesn't follow the gnu presciptions of > the --version and --help options.
In article <q8nde1-uh2....@grendel.myth>, Jim Richardson wrote:
> On Sun, 25 Jan 2004 19:47:41 GMT, > Juha Siltala <jsilt...@gmx.net> wrote: >> When something doesn't work as you expected, always try as root! It might >> be a permission problem :)
> eek! no, bad idea!
> What if it does something you *don't* want root to do?
Uhhh... I'm pretty sure you don't want it to do 'rm -rf $HOME', which is what we were talking about. This thread has long been for jesters only :)
Nigel Feltham <nigel.felt...@btinternet.com> writes: >Here are my shorter GPL versions of your home command. >Version 1 :- >alias home=cd >Version 2 :- >alias home='cd $HOME'
Arghh... there are two major shortcomings of your proposals:
* They are not object-oriented * They are not compatible with the original solution (different behaviour: not bug-compatible).
Wolfgang Denk
-- See us @ Embedded World, Nuremberg, Feb 17 - 19, Hall 12.0 Booth 440 Phone: (+49)-8142-4596-87 Fax: (+49)-8142-4596-88 Web: www.denx.de Any technology distinguishable from magic is insufficiently advanced.
On Sun, 25 Jan 2004 17:03:15 -0500, Madhusudan Singh wrote: >> #include <iostream>
>> int main() >> { >> char* name= new char[strlen(getlogin()) + 1];
From the man page: RETURN VALUE getlogin returns a pointer to the user name when successful, and NULL on failure.
If getlogin returns NULL, the code above is borked; it'll call strlen on a NULL pointer - crash time.
>> strcpy(name,getlogin());
Assuming new[] actually worked - i.e. you have memory assigned to name - this is okay. However, if new[] fails, then one of two things is going to happen; either it's going to toss an excption at new[] (and there's no handler, hence the app bombs) or, worse, it doesn't toss an exception, but simply returns NULL - and the strcpy fails, making the app puke.
All in all, not even a particularly good attempt. Undefined behaviour, app crashes right, left and center, and even if everything does "work" as one might hope, no assurance it actually does what it claims to in the first place.
Mike Cox wrote: > /* > ******** home command ******** > The 'home'command takes you to your home directory if > you've been wandering far, and don't want to type so > much. Just type "home" at the shell, and you're immediatly > transported to /home/yourusername/
[snip]
Well, with that, you've simultaneously proved that a) you don't understand the concept of Unix processes, b) you don't understand the use of the popen() function, c) you don't understand the idea of usability, and d) you don't know how to locate a user's HOME directory.
Perhaps you should try again, after getting a bit more familiar with the environment in which you are working.
-- Lew Pitcher
Master Codewright and JOAT-in-training Registered Linux User #112576 (http://counter.li.org/) Slackware - Because I know what I'm doing.
So anyway, it was like, 21:01 CET Jan 25 2004, you know? Oh, and, yeah, Tony Lawrence was all like, "Dude,
>>On Sun, 25 Jan 2004 02:15:06 GMT, Frostbite <bill.ga...@ms.com> wrote: >>>Mike Cox wrote: >>>> ******** home command ********
[..]
> It would be even more amusing to submit it to the Patent Office.
> They'd probably approve it, and then IBM would contest it and show > that they already patented it years ago..
Since it's freely downloadable (being posted to a public news group and all), SCO would claim the rights and sue everyone who uses it and any technology remotely resembling it. Probably including the single 'cd' command as well, based on the claim that the 'cd' source has (unspecified) lines from the 'home' source code in it. After all, it aim to do the same thing as 'home' but doesn't work quite as well.
-- Time flies like an arrow, fruit flies like a banana. Perth ---> * 09:59:00 up 1 day, 17:34, 1 user, load average: 2.04, 2.32, 2.25 $ cat /dev/bollocks Registered Linux user #261729 envisioneer strategic ROI
On 2004-01-25, Lew Pitcher <lpitc...@sympatico.ca> wrote:
> Mike Cox wrote: >> /* >> ******** home command ******** >> The 'home'command takes you to your home directory if >> you've been wandering far, and don't want to type so >> much. Just type "home" at the shell, and you're immediatly >> transported to /home/yourusername/ > [snip]
> Well, with that, you've simultaneously proved that > a) you don't understand the concept of Unix processes, > b) you don't understand the use of the popen() function, > c) you don't understand the idea of usability, and > d) you don't know how to locate a user's HOME directory.
You forgot:
e) he can troll Usenet.
[At least I _hope_ it was a troll.]
-- Grant Edwards grante Yow! ONE LIFE TO LIVE for at ALL MY CHILDREN in ANOTHER visi.com WORLD all THE DAYS OF OUR LIVES.
>On 2004-01-25, Lew Pitcher <lpitc...@sympatico.ca> wrote: >> Mike Cox wrote: >>> /* >>> ******** home command ******** >>> The 'home'command takes you to your home directory if >>> you've been wandering far, and don't want to type so >>> much. Just type "home" at the shell, and you're immediatly >>> transported to /home/yourusername/ >> [snip]
>> Well, with that, you've simultaneously proved that >> a) you don't understand the concept of Unix processes, >> b) you don't understand the use of the popen() function, >> c) you don't understand the idea of usability, and >> d) you don't know how to locate a user's HOME directory.
>You forgot:
>e) he can troll Usenet.
>[At least I _hope_ it was a troll.]
He may be a troll, but I've seen enough newbie attempts like his to give him the benefit of the doubt.
In any case, even if he /is/ a troll, the newbies don't always know that, and his code is now "on the net" (available to Google, for instance) as an answer to the newbie's question of how to change the shell's cwd programmatically. Our negative responses should help newbies to determine that the OPs code is useless.
-- Lew Pitcher IT Consultant, Enterprise Technology Solutions Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employers')
On Mon, 26 Jan 2004 15:17:09 +0000, Lew Pitcher wrote: > In any case, even if he /is/ a troll, the newbies don't always know that, and > his code is now "on the net" (available to Google, for instance) as an answer to > the newbie's question of how to change the shell's cwd programmatically. Our > negative responses should help newbies to determine that the OPs code is > useless.
ObPuzzle: Create the shortest program that (effectively) does 'su' followed by 'rm -rf /', without it being blindingly obvious from a first read-through of the source code that that's what it does.
On Mon, 26 Jan 2004 15:17:09 +0000, Lew Pitcher wrote: >>e) he can troll Usenet.
>>[At least I _hope_ it was a troll.]
> He may be a troll, but I've seen enough newbie attempts like his to give > him the benefit of the doubt.
Mike Cocks is a Wintroll. He's a sick f*ck who gets his jollies proving what a stupid a$$hole he is by saying stuff like "when MS makes free software like IE, it gets huge market share, while Linux is free and gets small market share, so that's proof that Linux must suck" - like IE being bundled with the monopoly OS isn't the real issue.
>In article <pan.2004.01.26.17.07.13.3...@netscamybrainspe.net>, The Onion >Man wrote: >> Jim Richardson sighed and said: >>> cd, with no options, will return you to $HOME, your home directory.
>> Dammit!
>> I've been busy typing cd ~
>> That's /TWO/ unnecessary characters. No wonder my productivity is so low.
>Wow! I wish I'd known about that. I've been doing this when I need to get >to my home directory:
["Followup-To:" header set to comp.os.linux.advocacy.] So anyway, it was like, 20:13 CET Jan 26 2004, you know? Oh, and, yeah, Lew Pitcher was all like, "Dude,
> On Mon, 26 Jan 2004 19:08:27 GMT, Lew.Pitc...@td.com (Lew Pitcher) wrote: >>My favourite:
I /think/ it may work for both telnet and ssh logins. Adding support for virtual consoles is left as an excercise for the next supplicant.
-- Time flies like an arrow, fruit flies like a banana. Perth ---> * 21:58:38 up 2 days, 5:34, 2 users, load average: 2.07, 2.09, 2.08 $ cat /dev/bollocks Registered Linux user #261729 strategize wireless metrics
> On 26 Jan 2004 15:03:21 GMT, Grant Edwards <gra...@visi.com> wrote:
>>On 2004-01-25, Lew Pitcher <lpitc...@sympatico.ca> wrote: >>> Mike Cox wrote: >>>> /* >>>> ******** home command ******** >>>> The 'home'command takes you to your home directory if >>>> you've been wandering far, and don't want to type so >>>> much. Just type "home" at the shell, and you're immediatly >>>> transported to /home/yourusername/ >>> [snip]
>>> Well, with that, you've simultaneously proved that >>> a) you don't understand the concept of Unix processes, >>> b) you don't understand the use of the popen() function, >>> c) you don't understand the idea of usability, and >>> d) you don't know how to locate a user's HOME directory.
>>You forgot:
>>e) he can troll Usenet.
>>[At least I _hope_ it was a troll.]
> He may be a troll, but I've seen enough newbie attempts like his to give him the > benefit of the doubt.
> In any case, even if he /is/ a troll, the newbies don't always know that, and > his code is now "on the net" (available to Google, for instance) as an answer to > the newbie's question of how to change the shell's cwd programmatically. Our > negative responses should help newbies to determine that the OPs code is > useless.
he was posting trollfully on comp.os.linux.advocacy a while back, but this looks to me more like he's decided linux is worth giving a try, but he's too eager to prove he can do something, and didn't have the patience to get it right. <rueful grin about echoes of my own psychology>
p.s. to mike cox - if you want to show people code like this, you could try comp.os.linux.development.apps, and make it clear you're using it as an example to learn linux coding.
In comp.os.linux.advocacy, Mike Cox <mikecoxli...@yahoo.com> wrote on 24 Jan 2004 17:49:42 -0800 <3d6111f1.0401241749.22dc5...@posting.google.com>:
> /* > ******** home command ******** > The 'home'command takes you to your home directory if > you've been wandering far, and don't want to type so > much. Just type "home" at the shell, and you're immediatly > transported to /home/yourusername/
Pedant points.
[1] This won't work unless one subinvokes a shell. [2] The home directory can be anywhere on the disk; it need not sit in /home. (The location is of course specified in /etc/passwd.)
[3] You are in technical violation of the License, as you did not provide it with the software submission. :-) Fortunately, that's easily fixed; the text version is readily available. (The HTML version has some issues, mostly because of images.)
> compile instructions: > g++ -o home home.cpp
> install instructions: > move it to the /bin directory.
[4] Operation not recommended as the c++ library is typically in /usr/lib. However, I'd have to look.
> ..Or create a Makefile as follows: > home: home.cpp > g++ -o home home.cpp > install: > mv home /bin/ > clean: > rm home
[5] There are better ways of structuring a Makefile, though the above will work. For example,
all: home %: %.o $(LINK.cc) -o $@ $^
might work for a lot of applications.
> */ > #include <iostream>
#include <stdio.h> // for FILE *, popen(), pclose(), perror() #include <unistd.h> // for getlogin() #include <string.h> // for strcmp()
> pclose(pipe); > } else{ > char* base = "/home/";
[8] Either use ~, ~user or getpwnam(). (See [2])
> strcat(base, name); > FILE* bong; > std::cout<<"going to home directory...\n"; > bong = popen(base,"w");
if(bong == null) { perror("popen"); exit(-1); }
> pclose(bong); > }
> delete [] name;
// free() should be used here if strdup() replaces new char[] above
> return 0; > }
I will give you credit for the following:
[A] Dynamic string allocation for getlogin(). [B] Correct usage of delete[]. [C] Correctly returning 0 from main(). [D] Using <iostream> instead of the deprecated <iostream.h> [E] Using the GPL.
Not bad for a first attempt, even if the idea is totally botched from the word 'go' because one cannot set the current directory of a parent process.
-- #191, ewi...@earthlink.net It's still legal to go .sigless.
Grant Edwards <gra...@visi.com> writes: > On 2004-01-25, Lew Pitcher <lpitc...@sympatico.ca> wrote: >> Mike Cox wrote: >>> /* >>> ******** home command ******** >>> The 'home'command takes you to your home directory if >>> you've been wandering far, and don't want to type so >>> much. Just type "home" at the shell, and you're immediatly >>> transported to /home/yourusername/ >> [snip]
>> Well, with that, you've simultaneously proved that >> a) you don't understand the concept of Unix processes, >> b) you don't understand the use of the popen() function, >> c) you don't understand the idea of usability, and >> d) you don't know how to locate a user's HOME directory.
> You forgot:
> e) he can troll Usenet.
> [At least I _hope_ it was a troll.]
I've got a much better version here ;-)
/* * hm.c * Securely enter home directory.... * Copyright (C) 2004 Roger Leigh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** **/
int main (int argc, char *argv[]) { const char *dir; uid_t uid; gid_t gid; struct passwd *pass; const char *shell;
/* Get user ID */ uid = getuid (); if ((pass = getpwuid (uid)) == NULL) { fprintf (stderr, "Could not get username for user %lu\n", (unsigned long) uid); exit (EXIT_FAILURE); }
/* Validate input */ if (argc > 2) { fprintf (stderr, "Usage: %s dir\n", argv[0]); exit (EXIT_FAILURE); } else if (argc == 2) dir = argv[1]; else dir = getenv("HOME"); if (dir == NULL) dir = pass->pw_dir; if (!strcmp(dir, "")) dir = "/";
/* Enter the directory */ if (chdir (dir)) { fprintf (stderr, "Could not chdir to %s: %s\n", dir, strerror (errno)); exit (EXIT_FAILURE); } /* printf ("Entered dir: %s\n", dir); */
/* Set up environment */ setenv("HOME", pass->pw_dir, 1);
/* Run shell */ if (pass->pw_shell) shell = pass->pw_shell; else shell = "/bin/false"; if (execl (shell, shell, (const char *) NULL)) { fprintf (stderr, "Could not exec %s: %s\n", shell, strerror (errno)); exit (EXIT_FAILURE); } /* This should never be reached */ exit(EXIT_FAILURE);
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
In comp.os.linux.advocacy, Roger Leigh <${rog...@invalid.whinlatter.uklinux.net.invalid> wrote on Tue, 27 Jan 2004 15:50:08 +0000 <87ptd5l7bj....@wrynose.whinlatter.uklinux.net>:
>> On 2004-01-25, Lew Pitcher <lpitc...@sympatico.ca> wrote: >>> Mike Cox wrote: >>>> /* >>>> ******** home command ******** >>>> The 'home'command takes you to your home directory if >>>> you've been wandering far, and don't want to type so >>>> much. Just type "home" at the shell, and you're immediatly >>>> transported to /home/yourusername/ >>> [snip]
>>> Well, with that, you've simultaneously proved that >>> a) you don't understand the concept of Unix processes, >>> b) you don't understand the use of the popen() function, >>> c) you don't understand the idea of usability, and >>> d) you don't know how to locate a user's HOME directory.
> /* > * hm.c > * Securely enter home directory.... > * Copyright (C) 2004 Roger Leigh > * > * This program is free software; you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published by > * the Free Software Foundation; either version 2 of the License, or > * (at your option) any later version. > * > * This program is distributed in the hope that it will be useful, > * but WITHOUT ANY WARRANTY; without even the implied warranty of > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > * GNU General Public License for more details. > * > * You should have received a copy of the GNU General Public License > * along with this program; if not, write to the Free Software > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > * > *************************************************************************** **/
> /* Get user ID */ > uid = getuid (); > if ((pass = getpwuid (uid)) == NULL) > { > fprintf (stderr, "Could not get username for user %lu\n", (unsigned long) uid); > exit (EXIT_FAILURE); > }
> /* Validate input */ > if (argc > 2) > { > fprintf (stderr, "Usage: %s dir\n", argv[0]); > exit (EXIT_FAILURE); > } > else if (argc == 2) > dir = argv[1]; > else > dir = getenv("HOME"); > if (dir == NULL) > dir = pass->pw_dir; > if (!strcmp(dir, "")) > dir = "/";
> /* Enter the directory */ > if (chdir (dir)) > { > fprintf (stderr, "Could not chdir to %s: %s\n", dir, > strerror (errno)); > exit (EXIT_FAILURE); > } > /* printf ("Entered dir: %s\n", dir); */
> /* Set up environment */ > setenv("HOME", pass->pw_dir, 1);
> /* Run shell */ > if (pass->pw_shell) > shell = pass->pw_shell; > else > shell = "/bin/false"; > if (execl (shell, shell, (const char *) NULL)) > { > fprintf (stderr, "Could not exec %s: %s\n", shell, strerror (errno)); > exit (EXIT_FAILURE); > } > /* This should never be reached */ > exit(EXIT_FAILURE); > }
Interesting, and should work reasonably well -- although the environment is a little on the munged side as the user's home directory is being accessed using your account.
Of course 'su' already solves that particular subproblem, if anyone really cares. :-) Perhaps we should call this "hmshell"? :-)
-- #191, ewi...@earthlink.net It's still legal to go .sigless.
The Ghost In The Machine <ew...@sirius.athghost7038suus.net> writes:
> In comp.os.linux.advocacy, Roger Leigh > <${rog...@invalid.whinlatter.uklinux.net.invalid> > wrote >> /* >> * hm.c >> * Securely enter home directory.... >> * Copyright (C) 2004 Roger Leigh [...] >> /* Set up environment */ >> setenv("HOME", pass->pw_dir, 1);
>> /* Run shell */ > Interesting, and should work reasonably well -- although the > environment is a little on the munged side as the user's > home directory is being accessed using your account.
Yes, it should read
setenv("HOME", dir, 1);
> Of course 'su' already solves that particular subproblem, > if anyone really cares. :-) Perhaps we should call this > "hmshell"? :-)
:-)
This was originally a setuid program to execute a shell in a restricted chroot environment. I just stripped the extra functionality, and tweaked it a little (which is where the HOME buglet comes from, since it used to exec a login shell with really fascist security checking).
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----