Operating System - HP-UX
1822469 Members
2717 Online
109642 Solutions
New Discussion юеВ

Re: chmod 775 on a symbolic link (not on its target)?

 
SOLVED
Go to solution
Romaric Guilloud
Regular Advisor

chmod 775 on a symbolic link (not on its target)?

How to change the mode of a symbolic link (thought first chmod -h would make it, then found out it does not since it's an option of chown, not chmod :-(
Thanks in advance.
Regards,
Romaric.
"And remember: There are no stupid questions; there are only stupid people." (To Homer Simpson, in "The Simpsons".)
4 REPLIES 4
Stefan Farrelly
Honored Contributor
Solution

Re: chmod 775 on a symbolic link (not on its target)?

You have to use the hidden lchmod() C function to change permissions on symbolic links - its the only way. Heres a C program which will allow you to do it, all you need to do is compile it;

cc -o lchmod lchmod.c

#include
#include
#include

#define assign_errno(x) ((errno != 0) ? errno : (x))

static void problem(msg,err)
char *msg;
int err;
{
(void) fprintf(stderr,"%s - (%d)\n",msg,err);
(void) fflush(stderr);
return;
} /* problem */

int main(argc,argv)
int argc;
char *argv[];
{
int cc = 0;
char s_err[512];

if (argc > 2)
{
mode_t mode = 0;
char *dummy = NULL;
int i = 2;

mode = (mode_t) strtoul(argv[1],&dummy,8);
while (i < argc && cc == 0)
{
cc = lchmod(argv[i],mode);
if (cc != 0)
{
cc = assign_errno(-1);
(void) sprintf(s_err,"%s failed. File '%s'",argv[0],argv[i]);
problem(s_err,cc);
}
++i;
}
}
else
{
cc = 255;
(void) sprintf(s_err,"Usage: %s Octal_Mode file1 [file2 ...]",
argv[0]);
problem(s_err,cc);
}
return(cc);
}
Im from Palmerston North, New Zealand, but somehow ended up in London...
Mark Grant
Honored Contributor

Re: chmod 775 on a symbolic link (not on its target)?

You do not need to do this because the modes of symbolic links are ignored. However, if you really want to, to make it all look pretty for example, you can always change your umask before creating the symbolic link.
Never preceed any demonstration with anything more predictive than "watch this"
Romaric Guilloud
Regular Advisor

Re: chmod 775 on a symbolic link (not on its target)?

Thank you for the piece of code Stefan; indeed it's for "esthetical" reasons that I needed this change.
Regards,
"And remember: There are no stupid questions; there are only stupid people." (To Homer Simpson, in "The Simpsons".)
Greg White
Frequent Advisor

Re: chmod 775 on a symbolic link (not on its target)?

Hello Romaric,

There was a thread very similar to this about a month earlier. I think that you will find that the actual author of that C code is none other than A. Clay Stephenson.

Please see the attached link for other ways to handle your problem.

http://forums1.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0xffcd12980463e24797ab1fdd8ed71fe0%2C00.html&admit=716493758+1066052317656+28353475

Greg
I know how to do it in pascal.