博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
I.MX6 su.c 测试
阅读量:7096 次
发布时间:2019-06-28

本文共 2722 字,大约阅读时间需要 9 分钟。

/************************************************************************* *                        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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* * 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 < 2) { uid = gid = 0; } else { pw = getpwnam(argv[1]); if(pw == 0) { uid = gid = atoi(argv[1]); } 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 == 3 ) { if (execlp(argv[2], argv[2], NULL) < 0) { fprintf(stderr, "su: exec failed for %s Error:%s\n", argv[2], strerror(errno)); return -errno; } } else if (argc > 3) { /* Copy the rest of the args from main. */ char *exec_args[argc - 1]; memset(exec_args, 0, sizeof(exec_args)); memcpy(exec_args, &argv[2], sizeof(exec_args)); if (execvp(argv[2], exec_args) < 0) { fprintf(stderr, "su: exec failed for %s Error:%s\n", argv[2], strerror(errno)); return -errno; } } /* Default exec shell. */ execlp("/system/bin/sh", "sh", NULL); fprintf(stderr, "su: exec failed\n"); return 1; }二、权限: chmod 4775 /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", };

 

转载地址:http://ewoql.baihongyu.com/

你可能感兴趣的文章
使用phpmyadmin导入SQL数据报错:#1062 - Duplicate entry '...
查看>>
Java Script 用对象属性模拟map 实现去重算法
查看>>
如何给按钮加上链接跳转功能
查看>>
ORACLE PL/SQL编程 游标
查看>>
micro:bit 的完整硬件方案
查看>>
bash shell快捷键
查看>>
Android判断是平板还是手机
查看>>
Nginx 499错误
查看>>
Spring Boot实践--集成WebServices基础开发
查看>>
使用history.back(-1)的问题
查看>>
ubuntu 重设crontab -e的默认编辑器
查看>>
[unity3d]unity中C#委托的应用
查看>>
我的友情链接
查看>>
gson 处理泛型
查看>>
pssh 自动化运维
查看>>
主机上的vsphere ha 代理无法访问其它主机的部分管理网络地址
查看>>
网站在架构时要考虑的事情
查看>>
MySQL修改root密码的多种方法
查看>>
android中WebView小结
查看>>
7、yum 学习笔记
查看>>