I.MX6 su.c 测试
/*************************************************************************
* 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 测试的更多相关文章
- I.MX6 2014 u-boot 测试修改
/************************************************************************* * I.MX6 2014 u-boot 测试修改 ...
- docker安装与测试 及 安装docker compose
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口 ...
- ansible hosts文件编写,简单使用测试(普通用户、sudo用户、root用户登录权限测试)
一.配置文件修改: 1.备份原配置文件: cp /etc/ansible/hosts /etc/ansible/hosts.bak 2.修改hosts配置文件: cat <<EOF> ...
- RHCSA试题分享
RHCSA 部分 密码破解 在linux16最后加入 rd.break 进入交换模式以后输入下列指令: mount -o remount,rw /sysroot chroot /sysroot pa ...
- Android开发-略讲adb命令和SQLite数据库运用
adb.exe ADB -Android Debug Bridge, 是 Android sdk 里的一个工具,用这个工具可以直接操作管理 Android 模拟器或者真实的 Android 设备 简 ...
- RHCE7.0练习题汇总[转]
RHCE7.0练习题汇总38 RHCSA部分 关于密码破解,在上午的考试中需要我们自己安装图形化界面和破解root密码,root的密码按照题目的要求来进行修改.可以使用单用户模式或者使用上课讲的re. ...
- (译)WebRTC实战: STUN, TURN, Signaling
http://xiaol.me/2014/08/24/webrtc-stun-turn-signaling/ 原文:WebRTC in the real world: STUN, TURN and s ...
- elasticsearch6.6及其插件安装记录(较详细)
借鉴网上资料并实施验证结果 elasticsearch6.6安装 安装包下载路径 https://www.elastic.co/downloads/elasticsearch 本文使用安装包 elas ...
- FreeRadius+GoogleAuthenticator实现linux动态口令认证
简介 在运维管理中,服务器的密码管理十分重要.服务器数量少的时候还好说,可以定时来改密码.一旦数量多了,再来改密码就不现实了. 前提 我们假定运维访问服务器是这样的: 创建一个普通用户用于登录服务器, ...
随机推荐
- Python列表的切片操作
在Python列表中分片是一个很重要的操作,有以下几个注意的点: 切片时不包含最后一位,如下例子中,要取最后一位,从0开始算应该是到7就可以取,但是需要8才能取 2. 默认取值步长为1,即每 ...
- Leetcode 309.最佳买卖股票时机含冷冻期
最佳买卖股票时机含冷冻期 给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格. 设计一个算法计算出最大利润.在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票): 你不 ...
- CodeForces 22、23部分题解
CodeForces 22A 找严格第二小的...注意只有一种情况,可以sort排序然后unique输出. int a[N]; int main() { int n; while(~scanf(&qu ...
- MTK GPIO 新增变量配置
主要涉及的文件: 1.需要配置preloader ,lk ,kernel vendor GPIO_YuSu.cmp文件增加IO别名: 2.需要配置preloader ,lk ,kernel vendo ...
- 【UOJ179】线性规划(单纯形)
题意: 思路:单纯形模板 ..,..]of double; idx,idy,q:..]of longint; c:..]of double; n,m,i,j,op,x,y:longint; eps,m ...
- <转>C#中线程的学习
原文发布时间为:2008-11-15 -- 来源于本人的百度文章 [由搬家工具导入] http://hi.baidu.com/cyap/blog/category/%B6%E0%CF%DF%B3%CC ...
- PHP 基础复习 2018-06-17
(1)AJAX Asynchronous JavaScript And XML(异步 JavaScript 及 XML) (2)创建 XMLHttpRequest 对象 不同的浏览器使用不同的方法来创 ...
- jquery的ajax提交时“加载中”提示的处理方法
方法1:使用ajaxStart方法定义一个全局的“加载中...”提示 $(function(){ $("#loading").ajaxStart(function(){ ...
- UVA 12035 War Map
让我先把微笑送给出题人 这个题最基础的一个想法:先找出一个度数和为总度数和的1/2的点集,然后判断这个点集和这个点集的补集能否形成二分图.但是就算我们把判断的复杂度看成O(1),这个算法的复杂度也是 ...
- CPU 天梯图