zoukankan      html  css  js  c++  java
  • Linux real uid 和 effective uid相关总结

    linux下real uid被用于描述用户是谁,文件的拥有者,effective uid指程序执行时的用户组别,用于判断程序是否有权去进行一些操作(例如读写文件),因此real uid是针对用户和文件(拥有者)而言,而effective是针对运行的程序而言。一般来讲一个用户执行一个程序,程序的effective uid会被设置为用户的real uid,这个effective uid与该程序的real uid(文件所有者)无关,只与执行者有关。

    来段代码:

     1 #include<stdio.h>
    2 #include<unistd.h>
    3
    4 int main(void){
    5 FILE *file;
    6
    7 fprintf(stdout, "real-uid %d\n", getuid());
    8 fprintf(stdout, "effective-uid %d\n", geteuid());
    9
    10 if((file = fopen("root_file", "w")) == NULL){
    11 perror("open root_file failed");
    12 }
    13 else{
    14 fprintf(stdout, "open root_file success\n");
    15 fclose(file);
    16 }
    17
    18 if((file = fopen("moon_file", "w")) == NULL){
    19 perror("open moon_file failed");
    20 }
    21 else{
    22 fprintf(stdout, "open moon_file success\n");
    23 fclose(file);
    24 }
    25
    26 return 0;
    27 }

    这段代码简单的执行对两个文件进行写操作。

    对程序而言,我们可以设置一个SUID,这个就是说用户执行这个程序时,程序的effective uid就不是当前用户的real uid了,而是这个程序(文件)拥有者的uid(即文件的所有者对应的real uid)。

    需要一提的是当前程序创建进程或线程时,effective uid会继承其uid,这点在编程时需要小心。

    寒,说的有点乱......

    ============================================================

    发现编码问题和时间问题真的很让人纠结...唉,希望之后的考试顺利~~

    加油~~~~

  • 相关阅读:
    DP——背包问题(三)
    堆——练习题
    DP——背包问题(二)
    二叉树的后序遍历(暴力版) 小白菜oj 1034
    树状数组2模板 Luogu 3368
    树状数组1模板 Luogu 3374
    DP——最长上升子序列(n^2与n log n)
    线段树(区间修改)模板题 Luogu 2357 守墓人
    c语言学习摘录
    python 学习摘录
  • 原文地址:https://www.cnblogs.com/aLittleBitCool/p/2308078.html
Copyright © 2011-2022 走看看