/*************************************************************************
* I.MX6 su.c 测试
* 说明:
* 今天突然想分析一下su的源代码,看一下其工作机制。
*
* 2016-8-10 深圳 南山平山村 曾剑锋
************************************************************************/ 一、su源代码修改:
/*
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/ #define LOG_TAG "su" #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h> #include <unistd.h>
#include <time.h> #include <pwd.h> #include <private/android_filesystem_config.h> /*
* SU can be given a specific command to exec. UID _must_ be
* specified for this (ie argc => 3).
*
* Usage:
* su 1000
* su 1000 ls -l
*/
int main(int argc, char **argv)
{
struct passwd *pw;
int uid, gid, myuid; /* Until we have something better, only root and the shell can use su. */
myuid = getuid();
// if (myuid != AID_ROOT && myuid != AID_SHELL) {
// fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
// // return 1;
// } if(argc < ) {
uid = gid = ;
} else {
pw = getpwnam(argv[]); if(pw == ) {
uid = gid = atoi(argv[]);
} else {
uid = pw->pw_uid;
gid = pw->pw_gid;
}
} // if(setgid(gid) || setuid(uid)) {
// fprintf(stderr,"su: permission denied\n");
// return 1;
// } /* User specified command for exec. */
if (argc == ) {
if (execlp(argv[], argv[], NULL) < ) {
fprintf(stderr, "su: exec failed for %s Error:%s\n", argv[],
strerror(errno));
return -errno;
}
} else if (argc > ) {
/* Copy the rest of the args from main. */
char *exec_args[argc - ];
memset(exec_args, , sizeof(exec_args));
memcpy(exec_args, &argv[], sizeof(exec_args));
if (execvp(argv[], exec_args) < ) {
fprintf(stderr, "su: exec failed for %s Error:%s\n", argv[],
strerror(errno));
return -errno;
}
} /* Default exec shell. */
execlp("/system/bin/sh", "sh", NULL); fprintf(stderr, "su: exec failed\n");
return ;
} 二、权限:
chmod /system/xbin/su 三、调用:
private static String cmdList[] = {
"su 0 netcfg can0 down",
"su 0 ip link set can0 type can bitrate 1000000 triple-sampling on",
"su 0 netcfg can0 up",
};

I.MX6 su.c 测试的更多相关文章

  1. I.MX6 2014 u-boot 测试修改

    /************************************************************************* * I.MX6 2014 u-boot 测试修改 ...

  2. docker安装与测试 及 安装docker compose

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口 ...

  3. ansible hosts文件编写,简单使用测试(普通用户、sudo用户、root用户登录权限测试)

    一.配置文件修改: 1.备份原配置文件: cp /etc/ansible/hosts /etc/ansible/hosts.bak 2.修改hosts配置文件: cat <<EOF> ...

  4. RHCSA试题分享

    RHCSA 部分 密码破解 在linux16最后加入 rd.break 进入交换模式以后输入下列指令: mount  -o remount,rw /sysroot chroot /sysroot pa ...

  5. Android开发-略讲adb命令和SQLite数据库运用

    adb.exe  ADB -Android Debug Bridge, 是 Android sdk 里的一个工具,用这个工具可以直接操作管理 Android 模拟器或者真实的 Android 设备 简 ...

  6. RHCE7.0练习题汇总[转]

    RHCE7.0练习题汇总38 RHCSA部分 关于密码破解,在上午的考试中需要我们自己安装图形化界面和破解root密码,root的密码按照题目的要求来进行修改.可以使用单用户模式或者使用上课讲的re. ...

  7. (译)WebRTC实战: STUN, TURN, Signaling

    http://xiaol.me/2014/08/24/webrtc-stun-turn-signaling/ 原文:WebRTC in the real world: STUN, TURN and s ...

  8. elasticsearch6.6及其插件安装记录(较详细)

    借鉴网上资料并实施验证结果 elasticsearch6.6安装 安装包下载路径 https://www.elastic.co/downloads/elasticsearch 本文使用安装包 elas ...

  9. FreeRadius+GoogleAuthenticator实现linux动态口令认证

    简介 在运维管理中,服务器的密码管理十分重要.服务器数量少的时候还好说,可以定时来改密码.一旦数量多了,再来改密码就不现实了. 前提 我们假定运维访问服务器是这样的: 创建一个普通用户用于登录服务器, ...

随机推荐

  1. HDU 4334 5-sum

    题目大意: 从5个集合中个选取一个数出来,使5个数相加之和为0 , 判断是否存在这种可能 因为集合数目最多200,那么200^3 = 8000000 , 那么这里很明显要把5个数拆成2个和3个计算,因 ...

  2. dispatching(bzoj 2008)

    Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级. ...

  3. solr请求处理器列表

    List of Request Handlers Available The Javadocs contain a complete list of Request Handlers. Many of ...

  4. DELL IDRAC API接口开发文档翻译及client模块

    今天和DELL官网要了一份关于服务器IDRAC 版本7/8 的API开发文档,花了一天的时间,进行了翻译,不一定全部准确,但对于英语不好的人会有所帮助.也不用重复造轮子了.下载链接: IDRAC AP ...

  5. P1195 口袋的天空 洛谷

    https://www.luogu.org/problem/show?pid=1195 题目背景 小杉坐在教室里,透过口袋一样的窗户看口袋一样的天空. 有很多云飘在那里,看起来很漂亮,小杉想摘下那样美 ...

  6. java自动识别用户上传的文本文件编码

    原文:http://www.open-open.com/code/view/1420514359234 经常碰到用户上传的部分数据文本文件乱码问题,又不能限制用户的上传的文件编码格式(这样对客户的要求 ...

  7. POJ 3264 Balanced Lineup(RMQ_ST)

    题目链接:http://poj.org/problem? id=3264 Description For the daily milking, Farmer John's N cows (1 ≤ N  ...

  8. android事件分发(二)

    非常早之前写过一篇android事件分发的博客,主要写的是它是怎样分发的,具体非常多原理的东西都没有涉及到.今天就从源代码看android怎样控制它的分发机制. 鉴于手机屏幕的限制,所以android ...

  9. 在Linux环境下使用TCP的keepalive机制

    Linux内置支持keepalive机制,为了使用它,你须要使能TCP/IP网络,为了可以配置内核在执行时的參数.你还须要procfs和sysctl的支持. 这个过程涉及到keepalive使用的三个 ...

  10. 关于Scrum

    最近某些产品经理发出下两周的工作计划的时候,喜欢带上sprint这个字眼,看上去貌似是要走敏捷开发这一套,只可惜,我觉得他表现出来的是对敏捷开发和Scrum一窍不通,甚至对软件开发流程都完全不清楚,居 ...