Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- Problems with exec families
General
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-06-2001 08:44 AM
03-06-2001 08:44 AM
Problems with exec families
i wrote this program
------------------------
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
-----------------------
but when i running this is the result
[jruiz@dns cgi]$ a.out jruiz
finger jruiz
Creacion:: Permission denied
[jruiz@dns cgi]$
-------------------------
what is the problem i know i have permition to see myself, is the same problem when the root own the program
------------------------
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
-----------------------
but when i running this is the result
[jruiz@dns cgi]$ a.out jruiz
finger jruiz
Creacion:: Permission denied
[jruiz@dns cgi]$
-------------------------
what is the problem i know i have permition to see myself, is the same problem when the root own the program
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-06-2001 09:40 AM
03-06-2001 09:40 AM
Re: Problems with exec families
The first arguement for execl is the pathname of a *FILE* which is to be executed. This means you need to write
if (execl("/usr/bin/finger","finger",cadena)<0) {
/* ... */
}
Also, what is the purpose of the line
cadena[strlen(cadena)]='\0';
If you can get string length, it is properly null-terminated. If it is not terminated or terminated, say, at 2040, this line is not going to help.
Regards,
Fellix
if (execl("/usr/bin/finger","finger",cadena)<0) {
/* ... */
}
Also, what is the purpose of the line
cadena[strlen(cadena)]='\0';
If you can get string length, it is properly null-terminated. If it is not terminated or terminated, say, at 2040, this line is not going to help.
Regards,
Fellix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-07-2001 12:06 AM
03-07-2001 12:06 AM
Re: Problems with exec families
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
/* the first parameter to any exec is
* the name/path of the program you wish to
* execute, thus:
* execl("/usr/bin/finger", "finger", cadena);
*/
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
Now ... as for argv[0], which is the second parameter, this is actually passed as a the zeroth argument to the program. While with something like finger it is not evident what the use may be, but some software programs use the zeroth argumnet rather niftily (is that a word yet?)
For example, gzip examines its own name (i.e, contents of argv[0]) and figures out if it is actually being called as 'gzip' or 'gunzip' and accordingly zips or unzips the subsequent arguments.
For instance, the attached example implements a slightly different version of the system utils 'basename' and 'dirname'
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
/* the first parameter to any exec is
* the name/path of the program you wish to
* execute, thus:
* execl("/usr/bin/finger", "finger", cadena);
*/
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
Now ... as for argv[0], which is the second parameter, this is actually passed as a the zeroth argument to the program. While with something like finger it is not evident what the use may be, but some software programs use the zeroth argumnet rather niftily (is that a word yet?)
For example, gzip examines its own name (i.e, contents of argv[0]) and figures out if it is actually being called as 'gzip' or 'gunzip' and accordingly zips or unzips the subsequent arguments.
For instance, the attached example implements a slightly different version of the system utils 'basename' and 'dirname'
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP