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动态口令认证
简介 在运维管理中,服务器的密码管理十分重要.服务器数量少的时候还好说,可以定时来改密码.一旦数量多了,再来改密码就不现实了. 前提 我们假定运维访问服务器是这样的: 创建一个普通用户用于登录服务器, ...
随机推荐
- 机器学习基础-Logistic回归1
利用Logistic回归进行分类的主要思想是:根据现有数据对分类边界线建立回归公式,以此进行分类. 训练分类器时的做法就是寻找最佳拟合参数,使用的时最优化算法. 优点:计算代价不高,利于理解和实现. ...
- dfs树上的边
by GeneralLiu 一 开 始 学 tarjan 的 强连通分量 , 割边 , 割点 时 没有 学扎实 经过培训 ,发现了些 需要注意的 小细节 举个荔枝 dfs树 上的 边 学了 tar ...
- HDU4462稻草人
l问题描述:有一块N*N的玉米田(N<=50),给定K个(X,Y)的坐标位置(K<=10)和相应的覆盖范围,请问,至少在这K个位置中选择几个放置稻草人,能保证玉米田全被覆盖? #i ...
- c:forEach varStatus 属性
c:forEach varStatus 属性 current: 当前这次迭代的(集合中的)项 index: 当前这次迭代从 0 开始的迭代索引 count: 当前这次迭代从 1 开始的迭代计数 fir ...
- 集群架构和CentOS7安装RabbitMQ集群(单机版)
1. 集群架构 1.1 四种内部元数据 队列元数据.交换器元数据.绑定元数据.vhost元数据. 单一节点中:会将数据存储到内存,同时将持久化元数据保存到硬盘. 集群中: 存储到磁盘上.内存中. 集群 ...
- codechef Taxi Driver
题意: 给N个点求任意两个点的“距离”总和: A,B的“距离”定义为:min(|ax-bx|,|ay-by|) (n<200000) 好题! 解析: 看着没思路 先是公式化简:让 ax=sx+s ...
- [Bzoj1015][JSOI2008]星球大战starwar(并查集)(离线处理)
1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 6849 Solved: 3204[Submit ...
- 北京交大yum
[base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever& ...
- @Aspect注解无效
Pointcut的execution配置正确的话,检查下,是否加了以下jar包 <!-- http://mvnrepository.com/artifact/org.aspectj/aspect ...
- IOS开发 AFN和ASI
做项目有一段时间了,项目过程中处理网络请求难免的,而对于选择第三方来处理网络请求肯定是个明智的选择! AFNetworking和ASIHTTPRequest 这两个第三方该如何选择 我 ...