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动态口令认证
简介 在运维管理中,服务器的密码管理十分重要.服务器数量少的时候还好说,可以定时来改密码.一旦数量多了,再来改密码就不现实了. 前提 我们假定运维访问服务器是这样的: 创建一个普通用户用于登录服务器, ...
随机推荐
- VIM键盘图
- F题
Problem F Codeforces 16E 这道题是一道数位Dp将鱼的死活列为0两种状态然后找DP关系 •题意:有n(n<=18)条鱼,接下来的n-1天,每天会有一对鱼(a,b)相遇,每天 ...
- hdu4352 XHXJ's LIS(数位DP + LIS + 状态压缩)
#define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the entire ...
- winrar5.0破解
RAR registration data Federal Agency for Education 1000000 PC usage license UID=b621cca9a84bc5deffbf ...
- SpringBoot自定义Filter
SpringBoot自定义Filter SpringBoot自动添加了OrderedCharacterEncodingFilter和HiddenHttpMethodFilter,当然我们可以自定 义F ...
- CodeForces - 750D New Year and Fireworks
因为 烟花的最大范围是各个方向150格 所以 最大的空间应该是 300*300 BFS和DFS均可 模拟每一个烟花爆炸的过程 但是要注意 需要一个数组来排重 在某一个爆炸点 如果爆炸的方向 和爆炸的层 ...
- Mysqli的常用函数
Mysqli的常用函数 连接数据库: $res = @mysqli_connect($host,$username,$pass,$db_name); if (mysqli_connect_errno( ...
- uva 11691
贪心 ~~ 使用优先队列 #include <cstdio> #include <cstdlib> #include <cmath> #include <se ...
- 51nod 1907(多项式乘法启发式合并)
题目: 分析: 对于一个确定的生成子图,很明显是在一个连通块上走,走完了再跳到另一个连通块上,假设连通块个数为cnt,那么答案一定是$min(a_{cnt-1},a_cnt,..,a_{n-1})$ ...
- linux otl oracle数据库连接例子
#include <string> #include <iostream> using namespace std; #define OTL_ORA10G //我连的是LI ...