I am using Ubuntu Lucid Lynx
is it possible to write data in a file through a C program which has read only permission. If it’s not possible, then is there any way to give sudo access to the C program.
For files without permissions, I would save the data in a string. Then i would open the file with write option:
FILE *fp = fopen(file_path,"w")
fputs(string,fp);
fclose(fp);
In Unix generally what you’d want to do is make the program’s executable owned by root, world executable, then set the SUID bit on it.
See chomd docs for exactly what the bits mean, but all together this means that whenever someone runs this executable, they get the executable process’ user ID set to the owner’s (root).